In my .vimrc file, I add few lines to it so that some file could have nice auto indent, such as .f90 and .c file, but it also cause autoindent for .plt file. Is there some way like if statement that could fix the problem such that the lines are working when I am working on .c or .f90 file and not working when I am working on .plt file?
1 Answer
The short answer (since I feel like I've written plenty about ftplugins before) is to use filetype plugins.
You need
filetype plugin on
at minimum for this to work.
Create e.g. ~/.vim/after/ftplugin/c.vim
and put e.g.
setlocal autoindent
You can also do this for fortran (.f90
).
Take out the autodindent
things from your vimrc, and you should be good to go.
I don't recognize the .plt
extension, and neither does my vim, but you could give it a filetype by doing
" ~/.vim/ftdetect/<name>.vim
autocommand BufRead,BufNewFile *.plt set filetype=<name>
And then put more filetype-plugin commands in ~/.vim/after/ftplugin/<name>.vim
.
Some might advocate for putting indent
related settings in ~/.vim/after/indent/<filetype>.vim
(and I would argue they are wrong; see :help indent-expression
, which says indent files are for setting 'indentexpr'
). If you do so, you'll need filetype plugin indent on
.
:help ftplugin