Search code examples
vimfile-type

Different set of characters to interpret as keyword for different files - vim


When I type w as for next word in vim, vim decides what is a word by searching the character set set by command :set iskeyword+=. I want to specify this settings per file type, so when I have >>= in haskell, it is interpreted as a word, but when I have <td>Field</td> in html it is not a whole word.

How can I do this in vim?


Solution

  • If you only want to enable an option for certain filetypes, use :setlocal option=value instead, and put the corresponding :setlocal commands into ~/.vim/after/ftplugin/{filetype}.vim, where {filetype} is the actual filetype (e.g. java). (This requires that you have :filetype plugin on; use of the after directory allows you to override any default filetype settings done by $VIMRUNTIME/ftplugin/{filetype}.vim.)

    Alternatively, you could define an :autocmd FileType {filetype} setlocal option=value directly in your ~/.vimrc, but this tends to become unwieldy once you have many customizations.