Probably every good program has a few irritating anti-features. One of Vim’s aggravating quirks is that it loads plugins after vimrc, which means that some of those plugins may or may not override some settings. (The most frustrating one for me is that I like to have formatoptions set to nothing, but many plugin devs have decided that they know my typing habits better than I do.)
Customizability is extremely important to me, and these plugins really begin to wreak havoc on my workflow.
Probably the best thing to do would be to track those plugins down and edit them manually. Whenever you find a setting that’s being overridden, in this example we’ll use formatoptions, run
:verbose set formatoptions?. This will tell you what offending script set it.
Unfortunately, this will likely only be an option if you have root access, because the plugins are in
/usr/share/vim/vimXX/* (where “XX” is the Vim version). I have this problem in Termux’s default Vim installation, but that’s resolvable because I have root access to edit these files. However, I’m currently in a situation with a client in which I don’t have root access.
There is a good workaround that I found online, but it’s not perfect. Unfortunately, the website has been down since before I even found the site, but the search results looked promising enough that I checked Google’s cache, and it revealed a pretty good solution. Kind of an obvious solution, but a good one nonetheless.
The direct link is here, but, as I write this, I haven’t been able to reach it (including while using a proxy server).
At any rate, since I don’t know how long Google keeps their cache up, I thought I’d go ahead and duplicate it here (with a few minor changes), in case the website is gone for good.
What we need to do is take advantage of Vim’s “after” functionality, so it will reload
$HOME/.vimrc after every plugin is loaded. (You may have some luck with
$MYVIMRC, but I’ve found that there are many cases in which
$MYVIMRC isn’t even set.) There’s a simple BASH script to do this, and it’s so short that I usually just type it directly into the terminal instead of making an individual script file.
(TL;DR version: Start here)
Please note that there’s a good chance that you’ll need to change the directory path from
/usr/share/vim/vim74 to something else. It was only recently that Vim updated to 8.0, and a lot of systems (mine included) don’t use it, and some are still on 7.1. You’ll just need to figure out what directory to use.
mkdir -p ~/.vim/after/ftplugin rm -i ~/.vim/after/ftplugin/* for file in /usr/share/vim/vim74/ftplugin/*.vim; do ln -s ~/.vimrc-after ~/.vim/after/ftplugin/`basename $file` done
Now, Vim will automatically load whatever’s in
$HOME/.vimrc-after after loading any plugin. I just put
source $HOME/.vimrc in mine. This means it’ll resource my vimrc every time it loads a plugin.
This is not ideal because it means resourcing a settings file every time you open a new file, but, from a pragmatic standpoint, it helps a whole lot more than it hurts.