Just a quick tip about Vim autocompletion.
I’ve been using the excellent SuperTab Vim Plugin for a couple years, it works reasonably well (autocompletes based on words from all buffers, file names, tags, context, etc…) but it doesn’t work really well for text that is split by dashes - CSS contains lots of these… - so I started to get frustrated with it.
You can change the auto complete behavior with
set iskeyword which also changes the behavior of standard motion commands like
b (it changes the word delimiters) – which a find a PITA since I got used to these motions. My quick and dirty solution to the problem was to keep
iskeyword with the minimal value as possible and only change it during
InsertEnter. That way I can still use
db to edit each fragment, autocomplete will work properly for words like
foo-bar__baz, and you can still use
E if you want to quickly jump around. For me that’s the best of both worlds!
function! KeywordsAll() setl iskeyword=@,48-57,192-255,\@,\$,%,-,_ endfunc function! KeywordsBasic() setl iskeyword=@,48-57,192-255 endfunc " improve the 'search word under cursor' behavior nnoremap * :silent call KeywordsAll()
* :silent call KeywordsBasic() nnoremap # :silent call KeywordsAll() # :silent call KeywordsBasic() augroup is_keyword " clear commands before resetting autocmd! " make sure `complete` works as expected for CSS class names whithout " messing with motions (eg. '.foo-bar__baz') and we make sure all " delimiters (_,-,$,%,.) are treated as word separators outside insert mode autocmd InsertEnter,BufLeave * :call KeywordsAll() autocmd InsertLeave,BufEnter * :call KeywordsBasic() " yes, we need to duplicate it on VimEnter for some weird reason autocmd VimEnter * nnoremap * :silent call KeywordsAll() * :silent call KeywordsBasic() autocmd VimEnter * nnoremap # :silent call KeywordsAll() # :silent call KeywordsBasic() augroup END
And here are my other autocomplete settings:
PS: I don’t recommend Vim to a new developer for the same reasons as described in this post, even tho I can’t see myself using another editor nowadays… – here is my complete .vimrc + some links in case you are interested.