Skip to content

Instantly share code, notes, and snippets.

@kshenoy
Last active October 7, 2015 16:37
Show Gist options
  • Select an option

  • Save kshenoy/3194474 to your computer and use it in GitHub Desktop.

Select an option

Save kshenoy/3194474 to your computer and use it in GitHub Desktop.
Vim function to perform easy retabs ( eg. change file with softtabstop=4 to softtabstop=2 )
function! ReTab( tabsize )
" Description: Change indentation when tab size is changed
" Primarily used to convert an indentation of eg. 4 to 2 or vice-versa
if &expandtab
let l:tabstop_old = &tabstop
let l:softtabstop_old = &softtabstop
let l:shiftwidth_old = &shiftwidth
let &tabstop = &softtabstop
set noexpandtab
retab!
let &tabstop = a:tabsize
set expandtab
retab!
let &tabstop = l:tabstop_old
let &softtabstop = a:tabsize
if (l:shiftwidth_old == l:softtabstop_old)
let &shiftwidth = a:tabsize
endif
else
let &tabstop = a:tabsize
endif
endfunction
command! -nargs=1 ReTab call ReTab(<args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment