Skip to content

Instantly share code, notes, and snippets.

@techpeace
Created October 24, 2011 19:08
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/1309857 to your computer and use it in GitHub Desktop.
Save techpeace/1309857 to your computer and use it in GitHub Desktop.
Dealing with tabstops in vim
" functions to deal with Tabs
command! Stab2 call Stab2()
function! Stab2()
let l:tabstop = 2
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
setlocal expandtab
endfunction
command! Stab4 call Stab4()
function! Stab4()
let l:tabstop = 4
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
setlocal noexpandtab
endfunction
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