Best way to organize file settings in .vim and .vimrc?

I look through my virtual files to clean them. I noticed that over time I added various specific file type parameters in various inconsistent ways. Suppose I configure Python:

  • au BufRead,BufNewFile *.py (do something) . I don't like this because some Python files may not have .py completion.

  • au FileType python (do something) . This seems like the best option since it is independent of the file with the .py ending. The disadvantage is that Vim is not aware of some file types. I can get Vim to recognize additional file types, but I also have various inconsistent ways to do this: a .vim/filetype.vim , another in .vim/after/filetype.vim and various set filetype in .vimrc .

  • Add a .vim/ftplugin/python.vim with specific file type settings. I understand that $VIMRUNTIME/ftplugin/python.vim can override all the settings I make here. One problem is that I'm not sure how this interacts with .vim/filetype.vim and .vim/after/filetype.vim .

  • Add .vim/after/ftplugin/python.vim . I understand that this loads after $VIMRUNTIME/ftplugin/python.vim so that it can overwrite the settings. As in the previous method, I'm not sure how it interacts with filetype.vim files.

So, I have at least four ways to do this, not to mention syntax files and file-specific plugins. It seems to me that the best way to do this is to set the specific parameters of the file in after/ftplugin so that they are not overwritten, and filetypes.vim in after for the same reason.

However, before continuing, I would like to ask if anyone has any suggestions on the best way to work with specific file type settings.

+44
vim file-type ftplugin
May 22 '10 at 21:05
source share
1 answer

I am saving Python-specific settings to $HOME/.vim/ftplugin/python.vim , since I cannot contrast anything with $VIMRUNTIME/ftplugin/python.vim .

Saving these parameters in the ftplugin file ftplugin my .vimrc nice and generic and easier to maintain (it is still quite large after more than ten years of using Vim).

If you want overrule , then ftplugin with your Vim distribution is configured, then $HOME/.vim/after/ftplugin/python.vim is what you want, since it is read after .

Similarly, $HOME/.vim/filetype.vim will be received before $VIMRUNTIME/filetype.vim , and this, in turn, will be received before $HOME/.vim/after/filetype.vim .

Call :scriptnames will contain a list of all named script sources in the order in which they were first received.

:help filetype provides fairly complete information about all this.

+63
May 23 '10 at 1:51 a.m.
source share



All Articles