Let's JAM!

Set Tab/Space Easily in Vim

I like tabs. Some of my co-workers prefer spaces. Neither of us will be convinced one way or another (easily), and so I work on both kinds of files. Backspacing a tab and replacing it with spaces was getting to be a pain in the butt, so I created a command named ST (set tab) to put in your ~/.vimrc to make switching between the two easy:


function! SetTab(spaces)

  let spaces = a:spaces

  if a:spaces > 0

    echo a:spaces

    execute 'set tabstop='.spaces

    execute 'set shiftwidth='.spaces

    execute 'set expandtab'


    set tabstop=5

    set shiftwidth=5

    set noexpandtab




command -nargs=? ST :call SetTab(<f-args>)


To change your space/tab settings all that needs to be done now is type:

:ST 0

to switch to tabs or

:ST 2

where 2 is how many spaces to change to.