Tabs in Vim

Tabs seem to be out of fashion in the programming world, there are perfectly valid arguments on both sides or the tabs vs. spaces flame war, illustrated with examples from every programming language and text editor combination ever made. You can read any or all of these if you are interested, but that isn’t the issue here.

I use tabs – all the time. My tab stopping is set to 4 spaces but my intention is to use actual tab characters. Its actually surprisingly hard to do this with vim. I’ve added the following lines to my .vimrc which allow me to see whether I have tabs or spaces at the start of the line.


set list listchars=tab:\|_,trail:.
highlight SpecialKey ctermfg=DarkGray

I fiddled with some other settings too, to try to stop everything ending up as spaces (I’m driving my colleagues mad) but to no avail. With these lines:


set shiftwidth=4
set softtabstop=4
set tabstop=4
set noexpandtab
set autoindent
set smartindent

I think those are all the relevant lines … it kind of works but I still need to type the set noexpandtab when I’m editing a file to stop auto-indented new lines from getting space instead.

Its all very exasperating so if anyone has suggestions other than “use spaces” I’d be interested to hear them!

One thought on “Tabs in Vim

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>