I have a file filename.fs with C-like syntax content. Vim opens it as a Forth source, and I use :set syntax=cpp to get the correct highlighting. But later when I try to jump between words I encounter that almost every set of chars is a word, so w goes almost always to end of line or so. I figured that this is related to iskeyword setting, and :verbose set iskeyword? gives me

       Last set from /usr/share/vim/vim74/syntax/forth.vim

So this appears to be also because of Forth-like suffix. I try doing set filetype=cpp, but this doesn't bring me the usual value of isk like @,48-57,_,192-255. It appears that the usual *.cpp-specific is set from /usr/share/vim/vim74/debian.vim, so it's not dependent on the file being cpp. But if I do e.g. :e newfile.cpp, then isk does get set to this default value even if before this I was editing a *.fs file.

So, my question is, how do I (re-)open my *.fs file as a non-Forth file, but without breaking the defaults for real Forth files and without need to manually set isk to the desired value?


You should use :setlocal filetype=cpp instead of :set syntax=cpp, but that still doesn't help you here.

The problem is that 'iskeyword' is set in $VIMRUNTIME/syntax/forth.vim, but it doesn't use the b:undo_ftplugin mechanism to undo that when the filetype changes (to cpp), so the modified option persists.

Fix A

If you never need to edit *.fs files as Forth, you can override the default filetype detection. Basically, create a file ~/.vim/filetype.vim with the following contents:

augroup filetypedetect
    au BufNewFile,BufRead *.fs         setf cpp
augroup END

See :help filetype-detect (and following paragraphs) for details. This is the most efficient setup.

Fix B

Alternatively, you can correct the omission by the syntax script via a file ~/.vim/ftplugin/forth.vim with these contents:

let b:undo_ftplugin = 'setlocal iskeyword<'
  • setlocal isk< does work after I do set filetype=cpp, but writing your full command to ~/.vim/ftplugin/forth.vim doesn't seem to automatically call this. Do I misunderstand what it actually should do? – Ruslan Apr 24 '15 at 16:53
  • Do you have :filetype plugin on in your .vimrc? Without it you have to write autocmd FileType forth let b:undo_ftplugin ... in your .vimrc. – Ingo Karkat Apr 24 '15 at 17:58
  • No, I don't, and when I tried adding it, it didn't seem to change anything... – Ruslan Apr 25 '15 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.