Saturday, June 30, 2012

Treat spaces as tabs only at the start of the line

I have sofftabstop (and shiftwidth) set to 4, and expandtab enabled. Thus, when deleting groups of spaces, vim treats them as tabs and deletes them 4 at a time. I want vim to do that only if from the start of the line and up to the cursor's position there's only spaces and nothing else.
Currently I'm doing the following:

inoremap <silent> <BS> <C-R>=fbs()<CR>

function fbs()
if getline('.') =~ '^ \{' . (col('.') - 1) . '}'
return "\<BS>"
endif
return "\<Left>\<Del>"
endfunction

It works, but it breaks the repeat (dot) command, and I don't want that :). I think it's because of the <Left>. Any help (either modifying the previous code so that it doesn't break the dot command or coming up with a new one that doesn't) is appreciated.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: