Dear all, I've recently started using the CleverTab function below, modified from the bottom of the comments page on tip 102. This is brilliant from my point of view:
- tab produces tabs at the start of the line for indenting*; - tab shows the longest unique option in the omnicomplete list when using omnicompletion; - tab cycles through the list of completions if the popup menu is visible but omnicompletion isn't used; - otherwise, it returns a tab. What I'd like to do is change the last one of those so that it puts in enough spaces to reach the next tabstop so that good formatting is maintained regardless of the tabstop setting on a users editor. However, I can't figure out how to achieve this. The 'expandtab' option is no use as it will change the tabs at the start of the line (used for indentation) to spaces, which will result in a really badly formatted piece of source code (as it is edited by several people who all like different tab stops)*. Similarly, replacing "\<Tab>" in the last return line with " " is no use as it will always insert four spaces, even if we're halfway through a tab stop (it's also not very flexible for different tabstop settings). Can anyone offer any suggestions for this? Cheers, Al function! CleverTab() " If we've only had spaces/tabs thus far, add a tab if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' return "\<Tab>" " If we're omnifuncing, act on it elseif exists('&omnifunc') && &omnifunc != '' return "\<C-X>\<C-O>" elseif pumvisible() return "\<C-N>" else " This should ideally be 'spaced tab' return "\<Tab>" endif endfunction * If anyone wants to try to preach about the soft tabs vs. hard tabs, please do it elsewhere. Having worked on a lot of collaborative projects, I have found that, for me, hard tabs for indentation and soft ones elsewhere is by far the best way of maintaining consistent and neat code. If you disagree, that's fine by me, to each their own, but please keep it to yourself and spare us all the pointless rants.