0

Here is the sshconfig syntax highlighting when i do not have any .vimrc file:

enter image description here

Let's create an empty .virmc :

$touch ~/.vimrc

Now let's edit that same file again:

enter image description here

Why is this happening? I'd like to use ~/.vimrc but not if it breaks syntax coloring. I am using brew-installed macvim on macOS Big Sur

1
3

That's because Vim is using $VIMRUNTIME/defaults.vim as the vimrc file.

If you look at :h .vimrc you'll see that Vim looks in five places for a vimrc file, stopping once it's found one.

When you have an empty personal vimrc (in your home directory, usually) then Vim will read that and stop searching. Obviously, if the file is empty there's no configuration of file type detection and, thus, no syntax highlighting.

When you don't have a personal vimrc then Vim continues down the list until it gets to the last item which is defaults.vim. This vimrc file includes filetype on and syntax on which enable file type detection and syntax highlighting, respectively.

Note that to truly work without a vimrc you'd need to use the -u NONE flag when you run Vim.

2
  • Oh that's surprising. Most configuration systems acquire "defaults" for each setting and then selectively override them with user-supplied values. I'll look up how to apply the vim defaults from within my .vimrc Aug 17 at 18:44
  • 1
    Indeed, this takes a lot of people by surprise. I think it's at least partly due to the fact that default configuration (i.e. no vimrc file at all) has become pretty outdated over the years (for instance, compatible is enabled...ick) so defaults.vim was added as kind of a user-friendly band aid. (FYI,add source $VIMRUNTIME/defaults.vim to the start of your vimrc if you want to include it.) Cheers.
    – B Layer
    Aug 17 at 18:47
0

Adding to @BLayer's [accepted] answer: the ~/.vimrc can "extend" the defaults.vim :

source $VIMRUNTIME/defaults.vim   " Add this to your ~/.vimrc

In this way we do not lose the world [default settings] for a penny [one particular setting].

1
  • Also runtime defaults.vim
    – D. Ben Knoble
    Aug 17 at 20:05

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.