On 27/10/06, Benji Fisher <[EMAIL PROTECTED]> wrote:
For another approach, pretty much what you suggested, look at the
VarTab() function in foo.vim, my file of example vim functions:
http://www.vim.org/script.php?script_id=72
This function returns a calculated number of spaces, and it should be
pretty easy to use the same idea for your function. (It just takes a
little :while loop.)
I've had a play with this approach and it looks like it works (I'd still
be interested to know how to solve the problem mentioned in my other
email of course). In case it's of interest to anyone, the
implementation is included below.
Cheers,
Al
set completeopt=menuone,longest
set noexpandtab
inoremap <Tab> <C-R>=CleverTab()<CR>
" A clever tab function
function! CleverTab()
" If we've only had spaces/tabs thus far, indent with a tab
if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
return "\<Tab>"
" If last character was a space, use spaces
elseif getline('.')[col(".")-2] =~ ' '
return GetSpacedTab()
" If we're 'omnifuncing', act on it
elseif exists('&omnifunc') && &omnifunc != ''
return "\<C-X>\<C-O>"
elseif pumvisible()
return "\<C-N>"
else
return GetSpacedTab()
endif
endfunction
function! GetSpacedTab()
" Find the first tab stop after the current column
" and return the number of spaces required to get there
let column = virtcol(".")-1
let tabstopwidth = &ts
let sofar = column % tabstopwidth
let remaining = tabstopwidth - sofar
let i = 0
let spaces = ""
while i < remaining
let spaces = spaces . " "
let i = i + 1
endwhile
return spaces
endfun