1

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
Edward Newell
  • 17,203
  • 7
  • 34
  • 36
  • For the time being, I've put `alias vim='vim -S ~/.vimrc'` in my .bash_profile to hack it, but I'd rather find *the right place* to put user-level preferences which ensures they're always read last. – Edward Newell Jun 12 '15 at 16:56
  • 3
    What are you actually trying to do? But the `after-directory` is what you are looking for. None of the files loaded after your vimrc should conflict with whats in your vimrc. (Or at least whats listed) – FDinoff Jun 12 '15 at 16:56
  • I'm trying to set `tabstop=4`. Script number 22 does clobber my tabstop setting. See my edit. – Edward Newell Jun 12 '15 at 22:41

1 Answers1

2

--- 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.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Vim finds my file, but the scripts loaded afterward clobber my `tabstop=4` setting. – Edward Newell Jun 12 '15 at 22:42
  • I don't think you understand my question. Where can I put a setting so that no other script would clobber it under any circumstances? – Edward Newell Jun 12 '15 at 23:54
  • 2
    I don't think you understand my answer. The "after" mechanism is precisely made for that but you are not supposed to use it for everything, only for the very few settings that can be overridden by ftplugins. – romainl Jun 13 '15 at 04:42
  • i.e. not an answer to the question. – Edward Newell Jun 13 '15 at 16:21
  • I appreciate your useful answer, but the question was **where or how can I get the last word on vim settings?**. If I'm not supposed to do that, why not? – Edward Newell Jun 13 '15 at 16:30
  • I answered your question. – romainl Jun 13 '15 at 17:57
  • Use an auto command as mentioned here. Use `filetype *` if you want global settings for all filetypes. Include more events if you want to override even more stuff. – 1983 Jun 23 '16 at 11:01