Where to put system-wide language-specific Vim ftplugin .vim files - vim

I've put some language-agnostic baseline settings in /etc/vimrc, which serve as default for users unless a user overrides them.
Where is the canonical system-wide place to put the respective {language}.vim files?
On a per-user basis, I've always put these in ~/.vim/ftplugin/{language}.vim, i.e. ~/.vim/ftplugin/python.vim might contain:
setlocal colorcolumn=72,80
However, this only kicks in for the given user.
Where should the system-wide version of ~/.vim/ftplugin/ sit? Should I directly edit /usr/share/vim/vim74/ftplugin/python.vim, or override it somewhere else?
Info:
Output of :scriptnames:
/etc/vimrc
/usr/share/vim/vim74/syntax/syntax.vim
/usr/share/vim/vim74/syntax/synload.vim
/usr/share/vim/vim74/syntax/syncolor.vim
/usr/share/vim/vim74/filetype.vim
/usr/share/vim/vimfiles/ftdetect/dockerfile.vim
/usr/share/vim/vimfiles/ftdetect/nginx.vim
/usr/share/vim/vimfiles/ftdetect/stp.vim
/usr/share/vim/vim74/ftplugin.vim
/usr/share/vim/vim74/syntax/nosyntax.vim
/usr/share/vim/vimfiles/plugin/cctree.vim
/usr/share/vim/vim74/plugin/getscriptPlugin.vim
/usr/share/vim/vim74/plugin/gzip.vim
/usr/share/vim/vim74/plugin/matchparen.vim
/usr/share/vim/vim74/plugin/netrwPlugin.vim
/usr/share/vim/vim74/plugin/rrhelper.vim
/usr/share/vim/vim74/plugin/spellfile.vim
/usr/share/vim/vim74/plugin/tarPlugin.vim
/usr/share/vim/vim74/plugin/tohtml.vim
/usr/share/vim/vim74/plugin/vimballPlugin.vim
/usr/share/vim/vim74/plugin/zipPlugin.vim
/usr/share/vim/vim74/ftplugin/python.vim
/usr/share/vim/vim74/syntax/python.vim
Output of :h runtimepath:
'runtimepath' 'rtp' string (default:
Unix: "$HOME/.vim,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
$HOME/.vim/after"
Amiga: "home:vimfiles,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
home:vimfiles/after"
PC, OS/2: "$HOME/vimfiles,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
$HOME/vimfiles/after"
Macintosh: "$VIM:vimfiles,
$VIMRUNTIME,
$VIM:vimfiles:after"
RISC-OS: "Choices:vimfiles,
$VIMRUNTIME,
Choices:vimfiles/after"
VMS: "sys$login:vimfiles,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
sys$login:vimfiles/after")

If you want to override /usr/share/vim/vim74/ftplugin/python.vim globally put your code into $VIM/vimfiles/after/ftplugin/python.vim (it's mentioned in :help runtimepath above); $VIM is usually /usr/share/vim so the exact path is /usr/share/vim/vimfiles/after/ftplugin/python.vim. Those plugins are executed after main plugins. Per-user overrides are in $HOME/.vim/after.
Verify paths with :echo &runtimepath.

Related

Why is vim picking up vimrc_example.vim and _vimrc?

I can't work this out, I thought vimrc_example.vim was an example file but turns out Vim is reading this file for some reason as well as _vimrc.
On windows 10 Home with Vim 8.2.24 not using gvim but vim.
The directory of both these files are:
C:\Program Files\Vim\_vimrc
C:\Program Files\Vim\vim82\vimrc_example.vim
When I delete vimrc_example.vim it does not start Vim properly then, it just starts with a blank screen then I have to push enter to start up vim. Somewhere my vim is telling it to read this file I just don't understand the how and why as I am new to vim.
The reason I realised this is I was trying to set tw=0 via _vimrc but turned out vimrc_example.vim kept overriding this and setting it back to 78. I have tried to google a solution to this, but I just thought common sense wise an example file should not be this relevant and if it is why?
Output of :scriptnames
1: C:\Program Files\Vim\_vimrc
2: C:\Program Files\Vim\vim82\vimrc_example.vim
3: C:\Program Files\Vim\vim82\defaults.vim
4: C:\Program Files\Vim\vim82\syntax\syntax.vim
5: C:\Program Files\Vim\vim82\syntax\synload.vim
6: C:\Program Files\Vim\vim82\syntax\syncolor.vim
7: C:\Program Files\Vim\vim82\filetype.vim
8: C:\Program Files\Vim\vim82\ftplugin.vim
9: C:\Program Files\Vim\vim82\indent.vim
10: C:\Program Files\Vim\vim82\autoload\plug.vim
11: C:\Program Files\Vim\vim82\ftoff.vim
12: C:\Program Files\Vim\vim82\syntax\nosyntax.vim
13: ~\.vim\plugged\vim-monokai\colors\monokai.vim
14: ~\.vim\plugged\vim-wakatime\plugin\wakatime.vim
15: ~\.vim\plugged\vim-airline\plugin\airline.vim
16: ~\.vim\plugged\vim-airline\autoload\airline\init.vim
17: ~\.vim\plugged\vim-airline\autoload\airline\parts.vim
18: ~\.vim\plugged\vim-airline\autoload\airline\util.vim
19: ~\.vim\plugged\vim-airline-themes\plugin\airline-themes.vim
20: ~\.vim\plugged\vim-clang-format\plugin\clang_format.vim
21: ~\.vim\plugged\vim-gitgutter\plugin\gitgutter.vim
22: ~\.vim\plugged\vim-gitgutter\autoload\gitgutter\utility.vim
23: ~\.vim\plugged\vim-gitgutter\autoload\gitgutter\highlight.vim
24: ~\.vim\plugged\vim-gitgutter\autoload\gitgutter\async.vim
25: ~\.vim\plugged\DrawIt\plugin\cecutil.vim
26: ~\.vim\plugged\DrawIt\plugin\DrawItPlugin.vim
27: C:\Program Files\Vim\vim82\plugin\getscriptPlugin.vim
28: C:\Program Files\Vim\vim82\plugin\gzip.vim
29: C:\Program Files\Vim\vim82\plugin\logiPat.vim
30: C:\Program Files\Vim\vim82\plugin\manpager.vim
31: C:\Program Files\Vim\vim82\plugin\matchparen.vim
32: C:\Program Files\Vim\vim82\plugin\netrwPlugin.vim
33: C:\Program Files\Vim\vim82\plugin\rrhelper.vim
34: C:\Program Files\Vim\vim82\plugin\spellfile.vim
35: C:\Program Files\Vim\vim82\plugin\tarPlugin.vim
36: C:\Program Files\Vim\vim82\plugin\tohtml.vim
37: C:\Program Files\Vim\vim82\plugin\vimballPlugin.vim
38: C:\Program Files\Vim\vim82\plugin\zipPlugin.vim
39: C:\Program Files\Vim\vim82\pack\dist\opt\matchit\plugin\matchit.vim
40: ~\.vim\plugged\vim-airline\autoload\airline\extensions.vim
41: ~\.vim\plugged\vim-airline\autoload\airline\extensions\quickfix.vim
42: ~\.vim\plugged\vim-airline\autoload\airline.vim
43: ~\.vim\plugged\vim-airline\autoload\airline\extensions\netrw.vim
44: ~\.vim\plugged\vim-airline\autoload\airline\extensions\term.vim
45: ~\.vim\plugged\vim-airline\autoload\airline\section.vim
46: ~\.vim\plugged\vim-airline\autoload\airline\highlighter.vim
47: ~\.vim\plugged\vim-airline\autoload\airline\extensions\hunks.vim
48: ~\.vim\plugged\vim-airline\autoload\airline\extensions\whitespace.vim
49: ~\.vim\plugged\vim-airline\autoload\airline\extensions\wordcount.vim
50: ~\.vim\plugged\vim-airline\autoload\airline\extensions\keymap.vim
51: ~\.vim\plugged\vimtex\autoload\vimtex.vim
52: ~\.vim\plugged\vim-airline\autoload\airline\extensions\vimtex.vim
53: ~\.vim\plugged\vim-airline-themes\autoload\airline\themes\molokai.vim
54: ~\.vim\plugged\vim-airline\autoload\airline\themes.vim
55: ~\.vim\plugged\vim-airline\autoload\airline\builder.vim
56: ~\.vim\plugged\vim-airline\autoload\airline\extensions\default.vim
57: ~\.vim\plugged\vim-gitgutter\autoload\gitgutter.vim
58: ~\.vim\plugged\vim-gitgutter\autoload\gitgutter\hunk.vim
https://i.gyazo.com/7ca9c5002ec1f95aa545c859b498cba5.png
Files:
_vimrc located in C:\program files\Vim\_vimrc:
http://dpaste.com/202QAN3
vimrc_example.vim located in C:\Program Files\Vim\vim82:
http://dpaste.com/2MWVY7V
You see I would think you could delete vimrc_example but not sure if it is doing anything important?????? Please refer to the specific line numbers if you wish to point out anything incorrect.
Your C:\Program Files\Vim\_vimrc has this on line 7:
" Vim with all enhancements
source $VIMRUNTIME/vimrc_example.vim
That's what's sourcing the vimrc_example.vim file. So it looks like you added this there, or copied it from somewhere (perhaps a guide or tip you found on the web?) or this _vimrc file is one you downloaded (or came with a Vim distribution you installed?) and had this in it already.
Anyways, that should explain why vimrc_example.vim is being sourced.
If you don't want that behavior anymore, you can either:
Remove that source command from C:\Program Files\Vim\_vimrc
Or, if you don't want to modify that specific _vimrc file (because it came with a distro or similar), then you can instead start using a _vimrc file from a different location (note that this one corresponds to the one listed as "3rd user vimrc file" in the :version output, you could use $HOME/_vimrc or $HOME/vimfiles/vimrc that come before it.)
Note that the vimrc_example.vim file is not really originally meant to be sourced this way... Instead, it's meant to be a template for you to copy to your own _vimrc that you can then modify to your taste. So while you'll probably be fine with sourcing it, it's not how it was meant to be used.
You'll also note that the vimrc_example.vim file doesn't actually have a lot of commands itself... But a lot of what it does is actually coming from defaults.vim that is sourced from it. Please note that the defaults.vim file is meant to be sourced from your vimrc (see :help defaults.vim for more details.)
So you might want to consider swapping the sourcing of vimrc_example.vim with the sourcing of defaults.vim. Additionally, if you like some of the other settings from vimrc_example.vim (such as enabling backup and undofile), consider replicating those into your vimrc.

How do I remove duplicates from vim :scriptnames file?

I'm trying to learn vim. When I open the program I'm met with this:
The airline statusline funcref function('airline#extensions#mundo#statusline') has already been added.The airline statusline funcref function('airline#extensions#mundo#statusline') has already been added.
The owner said:
that error message suggests that you have airline installed twice...
did you install airline globally as well as via vundle or something?
what does :scriptnames tell you? thanks.
Which was the case for the OP and what looks to be for me too. I ran :scriptnames and got the following references to airline:
56: ~/.vim/bundle/vim-airline/plugin/airline.vim
57: ~/.vim/bundle/vim-airline/autoload/airline.vim
58: ~/.vim/bundle/vim-airline/autoload/airline/init.vim
59: ~/.vim/bundle/vim-airline/autoload/airline/parts.vim
60: ~/.vim/bundle/vim-airline-themes/plugin/airline-themes.vim
78: ~/.vim/bundle/vim-airline/autoload/airline/extensions.vim
79: ~/.vim/bundle/vim-airline/autoload/airline/extensions/quickfix.vim
80: ~/.vim/bundle/vim-airline/autoload/airline/extensions/netrw.vim
81: ~/.vim/bundle/vim-airline/autoload/airline/extensions/ctrlp.vim
82: ~/.vim/bundle/vim-airline/autoload/airline/extensions/commandt.vim
83: ~/.vim/bundle/vim-airline/autoload/airline/extensions/branch.vim
84: ~/.vim/bundle/vim-airline/autoload/airline/extensions/syntastic.vim
85: ~/.vim/bundle/vim-airline/autoload/airline/extensions/whitespace.vim
86: ~/.vim/bundle/vim-airline/autoload/airline/extensions/wordcount.vim
87: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tmuxline.vim
88: ~/.vim/bundle/vim-mundo/autoload/airline/extensions/mundo.vim
89: ~/.vim/bundle/vim-airline/autoload/airline/section.vim
90: ~/.vim/bundle/vim-airline/autoload/airline/highlighter.vim
91: ~/.vim/bundle/vim-airline/autoload/airline/themes/dark.vim
92: ~/.vim/bundle/vim-airline/autoload/airline/themes.vim
93: ~/.vim/bundle/vim-airline/autoload/airline/util.vim
99: ~/.vim/bundle/vim-airline/autoload/airline/builder.vim
100: ~/.vim/bundle/vim-airline/autoload/airline/extensions/default.vim
What I don't know (and what I think I need help with) is the location of the file :scriptnames references and how to remove duplicates.
Thanks for your thoughts.
Most Vim plugins consist of several script files. It is therefore normal to see multiple references in :scriptnames. In your output, the base Airline directory is ~/.vim/bundle/vim-airline; all of these base directories have a common substructure under them (usually autoload/... and plugin/...).
What the owner meant was to check for multiple base directories, e.g. both ~/.vim/bundle/vim-airline and ~/.vim/bundle/vim-another-airline. Based on your output, that doesn't seem to be the case. Also, the error is about the Mundo extension for Airline, not Airline itself. Shouldn't you then look for multiple installations of Mundo?!
If you have two same plugins installed, you need to uninstall vim-airline. You will be having two lines of Plugin vim-airlines or something similar in vimrc. The exact names for plugins might be different. Delete any duplicate lines and run
:PluginUpdate
:PluginClean
Hope this helps

the dollar sign `$` cannot be removed from iskeyword [duplicate]

In my vimrc, I have included a script (say, otherscript.vim, which I need to include for work reasons) that says:
autocmd FileType php setlocal iskeyword+=$
and I don't want this behaviour. So, sometime later in the vimrc, I say:
autocmd FileType php setlocal iskeyword-=$
(I also tried using set instead of setlocal.) But, when I open a php file, iskeyword still contains the $ symbol in it. I am using vim 7.2. The output of ':verbose set iskeyword' is
iskeyword=#,48-57,_,192-255,$
Last set from /path/to/otherscript.vim
The output of ':scriptnames' is:
...
7: /usr/share/vim/vim72/ftplugin.vim
8: /home/yogeshwer/.vimrc
...
74: /path/to/otherscript.vim
...
Can somebody help me how I can revert the changes to 'iskeyword' made by the other script? Thanks a bunch.
I like to avoid autocmds when I can and use the after directory structure.
$ mkdir -p ~/.vim/after/{ftplugin,syntax,indent}
$ echo 'setlocal iskeyword-=$' >> ~/.vim/after/ftplugin/php.vim
This sets up a basic after directory in your user-specific vim config folder. Whereas ~/.vim/ftplugin/$FILETYPE.vim would be used in lieu of vim's standard $FILETYPE.vim file, files in an after directory get executed after, allowing you to override or change the behavior of your ftplugins, syntax definitions, and indent commands.
As an additional example to show you how these work, I'll include part of my local after/syntax/python.vim file here. I like all the "structural punctuation" of my code to stand out when I read it, so I do this:
syn match pythonParen /[()]/
syn match pythonBrack /[][]/
syn match pythonCurly /[{}]/
hi def link pythonParen Paren
hi def link pythonBrack Brack
hi def link pythonCurly Curly
I've also got an after/indent/php.vim file that was supposed to fix some of the annoying indent issues I ran into with the indent behavior when switching in and out of <?php ?> regions in a template file, but the code is a mess and never really worked in the first place, so I won't reproduce it here. I mention it only to give you an example of what can be done with the after hooks.

Vim loading multiple syntax files instead of just one

I have put new javascript syntax and indent files in my 'bundle' directory (I use Pathogen). I noticed that VIM loads both my new files as well as the standard files, in particular it loads the standard files after and I fear it may be overwriting the custom ones.
The VIM docs says it should not load the standard files if it found custom one first so I am not sure why this is happening.
This is what I see with the :scriptnames command, you can see the standard files (line 32, 35) after the customer ones (line 31, 34)
31: /usr/share/vim/vimfiles/bundle/vim-javascript/syntax/javascript.vim
32: /usr/share/vim/vim73/syntax/javascript.vim
33: /usr/share/vim/vim73/ftplugin/javascript.vim
34: /usr/share/vim/vimfiles/bundle/vim-javascript/indent/javascript.vim
35: /usr/share/vim/vim73/indent/javascript.vim
It's fine that both the system-default and your custom syntax files appear in the :scriptnames output. Vim will source all files found in 'runtimepath', but the canonical include guard
if exists("b:current_syntax")
will cause all scripts running after the first to abort immediately after the check.

Removing a character from 'iskeyword' in vim

In my vimrc, I have included a script (say, otherscript.vim, which I need to include for work reasons) that says:
autocmd FileType php setlocal iskeyword+=$
and I don't want this behaviour. So, sometime later in the vimrc, I say:
autocmd FileType php setlocal iskeyword-=$
(I also tried using set instead of setlocal.) But, when I open a php file, iskeyword still contains the $ symbol in it. I am using vim 7.2. The output of ':verbose set iskeyword' is
iskeyword=#,48-57,_,192-255,$
Last set from /path/to/otherscript.vim
The output of ':scriptnames' is:
...
7: /usr/share/vim/vim72/ftplugin.vim
8: /home/yogeshwer/.vimrc
...
74: /path/to/otherscript.vim
...
Can somebody help me how I can revert the changes to 'iskeyword' made by the other script? Thanks a bunch.
I like to avoid autocmds when I can and use the after directory structure.
$ mkdir -p ~/.vim/after/{ftplugin,syntax,indent}
$ echo 'setlocal iskeyword-=$' >> ~/.vim/after/ftplugin/php.vim
This sets up a basic after directory in your user-specific vim config folder. Whereas ~/.vim/ftplugin/$FILETYPE.vim would be used in lieu of vim's standard $FILETYPE.vim file, files in an after directory get executed after, allowing you to override or change the behavior of your ftplugins, syntax definitions, and indent commands.
As an additional example to show you how these work, I'll include part of my local after/syntax/python.vim file here. I like all the "structural punctuation" of my code to stand out when I read it, so I do this:
syn match pythonParen /[()]/
syn match pythonBrack /[][]/
syn match pythonCurly /[{}]/
hi def link pythonParen Paren
hi def link pythonBrack Brack
hi def link pythonCurly Curly
I've also got an after/indent/php.vim file that was supposed to fix some of the annoying indent issues I ran into with the indent behavior when switching in and out of <?php ?> regions in a template file, but the code is a mess and never really worked in the first place, so I won't reproduce it here. I mention it only to give you an example of what can be done with the after hooks.

Resources