Set nocompatible
When you use a separate vimrc through the -u
command-line flag, the nocompatible
option will not be automatically set, as it is when using the normal user vimrc file.
See :help compatible-default
for more details.
You should either add set nocompatible
to the top of your alternative vimrc file, or pass Vim the -N
command-line option in addition to -u
when using an alternative vimrc file.
Thanks @Rich for figuring out nocompatible
was likely the issue here, later confirmed by @Aericura.
Plug-ins are loading, just not working
Your listing of :scriptnames
shows that the UltiSnips plug-in is being loaded. The fact that it isn't working for you seems to be unrelated to passing an alternative vimrc file through the -u
option, but probably due to some command from your original vimrc that's missing from your alternative vimrc and that you didn't realize was important to make UltiSnips work for you.
You might want to do a few experiments, such as copying your original vimrc file (which is working) to a different name and passing that new file to the -u
flag. You should see that this configuration will be working, same as your original vimrc.
Another experiment is to make a back up copy of your original vimrc and deploy your alternative one in its place, as ~/.vimrc
(assuming that's the path of your original vimrc file.) You should verify that this setup is also not working, same as starting Vim with the alternate vimrc through the -u
flag.
If you check that this is indeed the case, then try to figure out what else is missing from your original vimrc to make UltiSnips work. You seem to be copying the global variables already, so that's probably not it... Do you perhaps have any key mappings to functions defined by UltiSnips that you're missing?
Make sure you're in nocompatible
mode as well, maybe add set nocompatible
to the top of your alternative vimrc. Make sure you also enable filetype processing, with filetype plugin indent on
. (It's unlikely one of these is the cause of your issue, but it's worth mentioning since they're easy to try.)
Sharing vim-plug configuration
Same plugins for every .vimrc file (vim-plug)
Answering your question from the title, having the same vim-plug stanza in every vimrc file should be enough to load the same plug-ins on Vim regardless of which .vimrc you're using, either the paths searched by default, or through the -u
command-line flag.
If you want to avoid repeating that information into multiple vimrc files, consider storing it on a separate file, such as ~/.vim/load-plugins.vim
and loading it using :source
or :runtime
.
If you store it in the location above, then this command should be enough to load it:
runtime load-plugins.vim
Add the command above to all your vimrc alternatives, they will then share the same plug-ins and same plug-in configuration (assuming you also keep the configuration for the plug-ins in that same file.)
Alternative: packages
If you're using Vim 8 or higher, or NeoVim, then consider using Vim packages instead of a plug-in manager such as vim-plug.
Your plug-ins are loaded from a standard location under your ~/.vim
, so you don't need any configuration in your .vimrc
to load the plug-ins, so that also solves that problem.
One difference between a plug-in manager such as vim-plug and native packages is that the former is able to install and update plug-ins for you (typically from Git repositories), while with packages it's on you to download them or git clone
them in the proper location and to update them there.
See this excellent answer with a description of packages and instructions on how to use them.
There should be only one
Finally, take a closer look at the reasons why you're using a separate vimrc. Are you using it to edit specific types of files?
In many cases, you might be able to trigger the specific kind of behavior you're customizing by triggering it based on the type of file you're editing. (Or you can use other specific triggers to enable your custom behavior.) That should prevent the whole "maintaining multiple vimrc files" mess. It should also make it easier to reuse your customizations for a specific filetype in other situations, other machines (not really tied to your custom vimrc.)
If you're interested in this approach, I suggest you ask further questions here, detailing your particular use case and trigger, to get help into how you can refactor that into a set of filetype-specific customizations.
.vimrc2
wouldn't work... If you use:scriptnames
in that setup, do you not see the plug-in files in ultisnips being called?11: ~/.vim/plugged/ultisnips/plugin/UltiSnips.vim
tells me UltiSnips is being installed... Why do you say it's not working? Perhaps it's not loading the snippets from the right location? Where do you have your snippets, is that location configured in your original.vimrc
?