I flip between Ruby and Markdown files a lot. Is there a way that I can have
set spell automatically set when I open a
*.md file, but not when I open a
The best way to set an option for a particular filetype is to use autocommands.
Here you could add something like that in your
autocmd FileType markdown setlocal spell
This line will trigger the command
setlocal spell when the filetype of a buffer is set as markdown. you can also use the autocommand based on the extension of the file you edit with something like:
autocmd BufRead,BufNewFile *.md setlocal spell
EDIT Using autocommands is not the best way to do that.
First, if you use the autocommands remember to put them in an
augroup markdownSpell autocmd! autocmd FileType markdown setlocal spell autocmd BufRead,BufNewFile *.md setlocal spell augroup END
This way if you source your vimrc several times the autocommands won't stack and get executed several times.
Now a better solution would be to use a ftplugin. To do that you want to create the file
This file will be sourced when the filetype of a buffer is set to
markdown and after the
ftplugin which comes with Vim by default has been sourced (this way you don't loose the already existing settings).
In this file you can simply add:
Here you need to use
setlocal instead of
set to make sure that the settings will only apply to the current buffer and not to all buffers.
Some interesting related help topics: