Last active
October 7, 2015 16:37
-
-
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 )
This file contains hidden or 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
| 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