Re: and expandtabs
- On Thu, Jul 29, 2004 at 04:54:45PM +0200, Alexander Rødseth wrote:
> In lack of any other solutions, I wrote a Python-script and added two lines to
> my .vimrc. If anybody has an even better solution, or any improvements, it is
> warmly welcomed.
> --- Here's the two lines:
> inoremap <silent> <Del> <ESC>:pyfile ~/.vim/delete.py<CR>i
> nnoremap <silent> <Del> :pyfile ~/.vim/delete.py<CR>
> --- And here's the script:
> # A Python script for the delete key
> # by Alexander Rødseth, 29.07.04
> # Use for whatever you like
I am still catching up on old questions; perhaps I could have saved
you some work if I had answered sooner. I have not tested this much,
except to check for whether I am off by one or not. To avoid problems
with the start or end of the line, I use the old trick of inserting a
"extra" character, so the <Esc> reliably lands me on that character.
Then I figure out how much to delete, delete it, and use "s" to return
to Insert mode.
inoremap <Del> x<Esc>:call SmartDel()<CR>s
let c = col(".")
let v = virtcol(".")
" The maximum number of characters to delete, if there are many spaces:
let num = &tabstop - ((v - 1) % &tabstop)
" Get num characters after the extra character.
let snip = strpart(getline("."), c, num)
" Only keep leading white space.
let white = matchstr(snip, '\s*')
" If there are no tabs, do nothing. If there are, throw away everything
" after the first tab.
let white = substitute(white, '\t.*', '\t', '')
execute "normal! d" . strlen(white) . "l"
HTH --Benji Fisher