Vim: last word on user specific settings?

256 views Asked by At

I have a nice .vimrc file with my preferred settings. One of the settings is tabstop=4. But when I'm on a server that I often work on, the tabstop setting that I apply in my ~/.vimrc gets clobbered by a script that's loaded later (/usr/share/vim/vim74/ftplugin/python.vim). Those scripts are owned by root, and I can't change them. Nor do I want to. I just want the last word on any given setting.

Where or how can I get the last word on vim settings?


if I start vim and do :scriptnames, I get this output:

1: /usr/share/vim/vimrc
2: /usr/share/vim/vim74/debian.vim
3: /usr/share/vim/vim74/syntax/syntax.vim
4: /usr/share/vim/vim74/syntax/synload.vim
5: /usr/share/vim/vim74/syntax/syncolor.vim
6: /usr/share/vim/vim74/filetype.vim
7: ~/.vimrc
8: /usr/share/vim/vim74/indent.vim
9: /usr/share/vim/vim74/ftplugin.vim
10: /usr/share/vim/vim74/syntax/nosyntax.vim
11: /usr/share/vim/vim74/plugin/getscriptPlugin.vim
12: /usr/share/vim/vim74/plugin/gzip.vim
13: /usr/share/vim/vim74/plugin/matchparen.vim
14: /usr/share/vim/vim74/plugin/netrwPlugin.vim
15: /usr/share/vim/vim74/plugin/rrhelper.vim
16: /usr/share/vim/vim74/plugin/spellfile.vim
17: /usr/share/vim/vim74/plugin/tarPlugin.vim
18: /usr/share/vim/vim74/plugin/tohtml.vim
19: /usr/share/vim/vim74/plugin/vimballPlugin.vim
20: /usr/share/vim/vim74/plugin/zipPlugin.vim
21: /usr/share/vim/vim74/indent/python.vim
22: /usr/share/vim/vim74/ftplugin/python.vim
23: /usr/share/vim/vim74/syntax/python.vim
24: /usr/share/vim/vim74/scripts.vim
25: /usr/share/vim/vim74/indent/vim.vim
26: /usr/share/vim/vim74/ftplugin/vim.vim
27: /usr/share/vim/vim74/syntax/vim.vim

EDIT
It's the script /usr/share/vim/vim74/ftplugin/python.vim that's clobbering my tabstop setting. If I do :verbose set tabstop I get:

  tabstop=8
    Last set from /usr/share/vim/vim74/ftplugin/python.vim
1

There are 1 answers

7
romainl On

--- edit ---

Put setlocal tabstop=4 in ~/.vim/after/ftplugin/python.vim or add these lines to ~/.vimrc:

augroup Python
    autocmd!
    autocmd Filetype python setlocal tabstop=4
augroup END

~/.vimrc is the right place to put most of your settings. For rare situations like this, when plugins override your settings, you have two possible strategies: autocommands and the after directory.

Using the after directory is somewhat "safer" but it has the downside of making your setup a bit more complicated. It is my recommended strategy. See :help after-directory.

Using autocommands is more "hacky" but it allows you to keep everything in one place. See :help autocommand.

--- endedit ---

You must use the -u flag to source a non-default vimrc:

$ vim -u /path/to/my/fancy/vimrc

But you don't have to do anything if your vimrc is located at the root of your $HOME directory.

Vim will find it and source it without any user intervention, as explained in :help startup, :help starting.txt and, more specifically, in :help vimrc.

In addition to all that reading, I'd suggest bookmarking this document for future reference.