Created
June 7, 2011 21:44
-
-
Save techpeace/1013245 to your computer and use it in GitHub Desktop.
A function that enables switching your tabstop configuration easily in vim.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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