Skip to content

Instantly share code, notes, and snippets.

@techpeace
Created June 7, 2011 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techpeace/1013245 to your computer and use it in GitHub Desktop.
Save techpeace/1013245 to your computer and use it in GitHub Desktop.
A function that enables switching your tabstop configuration easily in vim.
" from http://stackoverflow.com/questions/1562336/tab-vs-space-preferences-in-vim
" http://vimcasts.org/episodes/tabs-and-spaces/ is also worth checking out
" put all this in your .vimrc or a plugin file
command! -nargs=* Stab call Stab()
function! Stab()
let l:tabstop = 1 * input('set shiftwidth=')
if l:tabstop > 0
" do we want expandtab as well?
let l:expandtab = confirm('set expandtab?', "&Yes\n&No\n&Cancel")
if l:expandtab == 3
" abort?
return
endif
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
if l:expandtab == 1
setlocal expandtab
else
setlocal noexpandtab
endif
endif
" show the selected options
try
echohl ModeMsg
echon 'set tabstop='
echohl Question
echon &l:ts
echohl ModeMsg
echon ' shiftwidth='
echohl Question
echon &l:sw
echohl ModeMsg
echon ' sts='
echohl Question
echon &l:sts . ' ' . (&l:et ? ' ' : 'no')
echohl ModeMsg
echon 'expandtab'
finally
echohl None
endtry
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment