At moment, mostly for random reasons, I have
$ cat ~/.vim/ftplugin/c.vim set tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab smartindent autoindent cinoptions=g2
$ cat ~/.vim/ftplugin/cpp.vim let c_no_curly_error = 1 set tabstop=8 softtabstop=8 expandtab shiftwidth=8 smarttab smartindent autoindent cinoptions=g2 set mps+=<:>
where I've put
8s in the two files for debugging purpose.
:echo &tabstop gives
2 when I open a
*.cpp file (and also when I open a
*.c file, which is expected), I'm pretty sure I've put those files in the wrong place or, at least, some lines of those files in the wrong file and wrong place.
In Chapter 42 from Learn Vimscript the Hard Way I read the following
~/.vim/indent/are a lot like
ftpluginfiles. They get loaded based on their names.
indentfiles should set options related to indentation for their filetypes, and those options should be buffer-local.
Yes, you could simply put this code in the
ftpluginfiles, but it's better to separate it out so other Vim users will understand what you're doing. It's just a convention, but please be a considerate plugin author and follow it.
which tells me that, on the one hand,
~/.vim/indent/ would be a better place for filetype-specific Vim files containing
set tabstop=... ..., and on the other hand tells me that
~/.vim/ftplugin/ isn't that bad.
Nonetheless, If I move those two files from
:echo &tabstop gives the correct output of
*.cpp files and
This troubleshooting tells me that probably
~/.vim/ftplugin/ is a wrong place to put that setting, and
~/.vim/indent is maybe the right place.
- Is this the case?
If the answer is affirmative, then I know where I have to move
c.vim into, and that I have to create a
cpp.vim file beside that containing only the second line from the
cpp.vim which is above.
- As a side question, where should I put the other two options, which are not indentation specific? What is their most appropriate location?
setlocal(in both the
cpp.vimfiles). On the other hand many files in
setlocal, so doing this change is probably good for some other good reason.
setlocalkeeps the change local to that buffer (relevant if you have many buffers with different filetypes!). For personal stuff,
afteris also a good way to be sure your settings take effect no matter what