Saturday, June 14, 2014

Toggle Between Two and Four Spaces in Vim

To my fellow Vim users:

" Toggle between two and four spaces
let g:spaces = 2

function! TabToggle()
  if g:spaces == 2
    let g:spaces = 4
  else
    let g:spaces = 2
  endif
  echo "Switching to " . g:spaces . " spaces."
  let &tabstop     = g:spaces
  let &shiftwidth  = g:spaces
  let &softtabstop = g:spaces
endfunction

nmap <leader>t :call TabToggle()

Put that in your .vimrc and benefit.

No comments: