Creating a stab
option in Vim itself would not be easy, but I’ve whipped up this command/function that you can drop in your .vimrc
(or a plugin file if you’re super-organized). Use :Stab
and you will be prompted for an indent level and whether or not to use expandtab
. If you hit enter without giving it a new indent level, it will just print the current settings.
" 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