26

I started using Vim as it was first installed and then decided to change the indentation behavior by adding

set tabstop=8 softtabstop=0 expandtab shiftwidth=2 smarttab

to ~/.vimrc as suggested by https://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces. However, when I do so, syntax highlighting for my Python files is disabled. I assume it is probably disabled for other languages and that other settings are not set from the default configuration, as well, but haven't tested yet.

How do I keep the rest of the default settings and only modify the above settings for indentation? (Note: I did not have a ~/.vimrc before this. I created it and added the single line above.)

3 Answers 3

14

Your system default vimrc no longer gets loaded when you create your own (and that's as it should be).

You also won't get filetype based indenting and other things.

The solution is to add these lines to ~/.vimrc:

filetype indent plugin on
syntax on
5
  • 3
    What if I want to keep those "other things" as well? What can I do?
    – Code-Guru
    Commented Dec 3, 2016 at 1:41
  • 2
    Locate the file and add a :source command in your vimrc.
    – Heptite
    Commented Dec 3, 2016 at 1:42
  • How to locate the file ? Where can it be ?
    – xtof54
    Commented Oct 27, 2018 at 7:34
  • 6
    @xtof54 Without a ~/.vimrc, do :scriptnames
    – Heptite
    Commented Oct 27, 2018 at 14:31
  • 1
    source $VIMRUNTIME/defaults.vim
    – jabbat
    Commented Mar 4, 2021 at 19:38
14

Or you can move the content of your ~/.vimrc file to ~/.vim/plugin/CUSTOM_NAME.vim.

Vim will automatically load your configurations (without touching any other defaults)

2
  • 1
    This should be the correct answer, since it doesn't interfere with the defualt behavior. Thanks!
    – jlbenc
    Commented Mar 14, 2021 at 1:30
  • Yes, I needed this answer for MSYS2 (but not -- weirdly -- Cygwin)!
    – kevinarpe
    Commented Mar 7, 2022 at 16:07
2

What I found is that the vim installation didn't contain a system default vimrc at e.g. /etc/vimrc, but it did supply some settings in /etc/skel/.vimrc which resembled the default configuration, unlike what you get if you just do syntax on in an otherwise blank .vimrc, and could be copied to an existing account as a starting point.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .