-1

On my system vim has a "defaults.vim" file that is getting sourced. For example, if I do vim --version, I see the following:

   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"

The problem is that the defaults file has a bunch of annoying settings in it. How can I disable it? I had read elsewhere that as long as I had a ~/.vimrc file that the defaults file would not be loaded, but this is not true. I have a blank ~/.vimrc and defaults is still getting loaded. How can I prevent this?

4
  • Why do you have a blank .vimrc, and not one with your preferred settings?
    – Herb
    Jan 8, 2018 at 22:59
  • @HerbWolfe Because I am just using this server for 15 minutes. I do not want invest an afternoon in it. I just want the default settings OFF NOW. Jan 8, 2018 at 23:08
  • 1
    Are you certain the defaults aren't off? :version reports those files regardless of anything, it does not necessarily mean they're being loaded.
    – Mass
    Jan 9, 2018 at 1:27
  • 1
    This question could be improved if you told us 1) which default options you find annoying and 2) what result you do want as opposed to what you do not want. Please also share the output of :scriptnames.
    – Friedrich
    Dec 27, 2023 at 17:43

3 Answers 3

3

From :h defaults.vim:

If Vim is started normally and no user vimrc file is found, the $VIMRUTIME/defaults.vim script is loaded.

Perhaps an empty vimrc is the same as no vimrc...? Anyways, try this...

Near the start of $VIMRUNTIME/defaults.vim you'll see:

if exists('skip_defaults_vim')
  finish
endif

So put something like this near the start of your system vimrc and that should suppress it:

let skip_defaults_vim=1

Use of this variable in the system vimrc is documented: :h skip_defaults_vim

1
  • 1
    On my machines, I use let g:skip_defaults_vim = 1 in /etc/vim/vimrc.local and can confirm that it does work. Jan 9, 2018 at 9:04
1

Use the following command to start Vim without loading any initialization files.

Note the command is case-sensitive.

vim -u NONE -N

  • -u NONE prevents the loading of initialization files.
  • -N explicitly turns off Vi compatibility. This makes Vim behave normally.

You can test the result in Vim by using the :scriptnames command to show that no script files were loaded. (There should be no output, and Vim will return to Normal mode.)


Note that you have to type these options each time you run Vim.

If you are working in a terminal and are willing to modify your shell then you can create an alias for Vim where these options are automatically included each time Vim is run.

For example:

alias myvim="vim -u NONE -N"

myvim /home/user/some_file.txt

By using a unique alias like myvim, you can avoid a name collision with an existing application or alias.

2
  • 2
    Welcome to Vi and Vim SE. Note that vim --clean will source defaults.vim. You can see by running :scriptnames. Since OP isn't particularly clear about what he wants, this is as good an answer as any.
    – Friedrich
    Dec 27, 2023 at 14:14
  • 2
    Correct, if you want to disable loading defaults.vim, use vim -u NONE -N Dec 27, 2023 at 17:17
0

I "disable" it this way:

echo "set compatible" > ~/.vimrc

echo "export VIMINIT='source $HOME/.vimrc'" >> $HOME/.bashrc

. $HOME/.bashrc

I do not know if it is the "proper" way, but it seems to always work and allows me to put whatever I want in ~/.vimrc

I put all sorts of things in there to make vim as "vi-like" as I can, but the point is that I can set this for a given user and I do not need to change system-wide defaults.

1
  • You almost certainly don’t need VIMINIT if you’re using a ~/.vimrc file.
    – D. Ben Knoble
    Apr 19 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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