I need to test a vim plugin. The problem: I already have my vim setup in current env, so ~/.vimrc is occupied.

I want to issue a command like vim -u <blah..blah> that maybe specifies the plugin path and has some other options to enable testing the plugin only.


A general recommendation when debugging an issue is to start vim with -u NONE, which skips all initialization.

If you just want to start vim without plugins and with a custom .vimrc file start vim with the following command:

vim --noplugin -u <test_vimrc_file> <your_file_name>

then issue the command :packadd <package_name> to load the plugin you want to test.

  • Nice, but assume I have minimal vimrc, how to add packadd <package_name> in it to load only one plugin when start with minimal vimrc vim -u minimal-vimrc. I tried but it always load all in ~/.vim/pack/default/start, I get minimal-vimdc from here: gist.github.com/r00k/8fc7e4e9d35ccbfb64aa
    – Tuyen Pham
    Jan 20 '20 at 7:30
  • Use the vim --noplugin -u .minimal_vimrc. See :help load-plugins for details. Jan 20 '20 at 8:33
  • [Update: I've added it to my answer, since it answers better your original question.] Jan 20 '20 at 8:38

Try this:

set rtp-=~/.vim
set rtp-=~/.vim/after
set rtp^=/path/to/some-plugin
set rtp+=/path/to/some-plugin/after

set vif=NONE
filetype plugin indent on
syntax enable

Write the code in a file, e.g. /tmp/vimrc, then start Vim with this shell command:

vim -Nu /tmp/vimrc

The -u argument specifies the path to a custom vimrc, while the -N argument resets 'compatible'. -N is necessary, because:

  1. you probably don't want 'compatible' to be set
  2. when you pass any value different than DEFAULTS to -u, 'compatible' is set

See :h -u and :h -N.

Note that 'compatible' is always disabled in Nvim (see :h nvim-defaults), so you don't need -N for the latter:

nvim -u /tmp/vimrc

If the plugin you're testing doesn't contain an after/ directory, you can remove this line:

set rtp+=/path/to/some-plugin/after

Setting 'viminfofile' to NONE makes sure your viminfo file is not read; the contents of the latter could interfere while you're testing your plugin.

Note that in Nvim, 'viminfofile' is deprecated in favor of 'shadafile'; if you use it, replace set vif=NONE, with set sdf=NONE.

Also, if you use Nvim, you may be interested in making 'guicursor' empty:

set gcr=

Because Nvim sets 'guicursor' by default (even with -u NONE), which makes it send escape sequences to set the shape of the cursor; these sequences may not always be correctly understood by your terminal, and may interfere while you're testing your plugin.

If for some reason, you need some of your plugins to be sourced (matching ~/.vim/plugin/**/*.vim or ~/.vim/after/plugin/**/*.vim), try this instead:

set rtp-=~/.vim
set rtp-=~/.vim/after
set rtp^=/path/to/some-plugin
set rtp+=/path/to/some-plugin/after
set rtp^=~/.vim
set rtp+=~/.vim/after

set vif=NONE
filetype plugin indent on
syntax enable

If your plugin doesn't need:

  • syntax scripts, remove syntax enable
  • indent scripts, remove indent in filetype plugin indent on
  • filetype scripts, remove plugin in filetype plugin indent on
  • any of the above, remove the lines filetype plugin indent on and syntax enable

If you use UltiSnips, you could try this snippet:

snippet vimrc "Minimal vimrc to test a plugin" bm
set rtp-=~/.vim
set rtp-=~/.vim/after
set rtp^=${1:~/.vim/plugged/vim-${2:foo}}${3:
set rtp+=$1/after}${4:
set rtp^=~/.vim}${5:
set rtp+=~/.vim/after}

${6:set `!v has('nvim') ? 'sdf=NONE gcr=' : 'vif=NONE'`
}${7:filetype plugin indent on
syntax enable}


Some of the paths which are used in the set rtp settings assume you're using vim-plug as a plugin manager; if that's not the case, you'll need to edit this line:

set rtp^=${1:~/.vim/plugged/vim-${2:foo}}${3:

So that the path points to the directory of your plugin.

  • This answer shows how to create the requisite vimrc, but not the invocation of vim that would trigger it’s behavior.
    – D. Ben Knoble
    Jan 15 '20 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.