1

I'm using vim for writing C programs. And I like colours. The default tabsize is 8, which is pretty much unnecessary. So I changed it to 4 by after following this answer.

set tabstop=4
set shiftwidth=4
set softtabstop=0
set noexpandtab

Now, the problem is the colourful C program has become black and white(like Zebras). What's happening? Do I have to use 8 space for tabs(and indents) to avoid those zebra like colours?

Abinash Dash
  • 167
  • 1
  • 9

1 Answers1

0

In your vimrc, try also putting:

syntax enable

Per O.P.'s comment below:

it's better to add these 2 lines to .vimrc to revive default vim behaviour . unlet! skip_defaults_vim source $VIMRUNTIME/defaults.vim

I have added since the question has been accepted.


I imagine that you did not have a vimrc before and creating one changed the default settings.

When you do not have a vimrc, vim loads $VIMRUNTIME/defaults.vim to set defaults for you so that when you run vim you don't get basically get vi. When you create a vimrc, vim short-circuits and does not load any other vimrc nor does it load defaults.vim. This means that you have to set all of the settings you wish to set inside your vimrc; vim assumes that if you have a vimrc, then you're competent enough to set it as you desire.

Read more about it at :help defaults.vim

dylnmc
  • 3,810
  • 4
  • 26
  • 42
  • Yes. I didn't have any vimrc before. So I created one to change tab size. It seems vim wants this command to be added to vimrc explicitly. So I added this line and the colouring and auto indentation based on file type is working again. Thanks for hint @dylnmc. Found a tip for indentation fix [here](https://wiki.python.org/moin/Vim) – Abinash Dash Apr 07 '18 at 04:51
  • `filetype indent on` is the extra line I've added to fix auto indentation. – Abinash Dash Apr 07 '18 at 05:00
  • BTW, I checked `/etc/vim/vimrc` and almost all of the lines are commented out. One line which is not commented out probably tries to find and source `/etc/vim/vimrc.local` but there's no such file on my machine. which file vim uses to load settings(if .vimrc is absent)? I think that will complete the answer. – Abinash Dash Apr 07 '18 at 05:11
  • @AbinashDash updated, but yes I was mostly trying to point you in the right direction. Good luck, buddy – dylnmc Apr 07 '18 at 13:53
  • "This means that you have to set all of the settings you wish to set inside your vimrc; vim assumes that if you have a vimrc, then you're competent enough to set it as you desire." That was really a bad news for me. I'm a vi(m) beginner anyway. – Abinash Dash Apr 07 '18 at 14:21
  • 1
    it's better to add these 2 lines to .vimrc to revive default vim behaviour . `unlet! skip_defaults_vim source $VIMRUNTIME/defaults.vim` – Abinash Dash Jun 06 '19 at 09:40