Last active
December 17, 2015 19:39
-
-
Save kshenoy/5661828 to your computer and use it in GitHub Desktop.
Insert tabs at start of line and spaces elsewhere
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
function! VaryTabs() | |
" Description: Make <Tab> put tabs at start of line and spaces elsewhere | |
if &expandtab | |
return "\<Tab>" | |
else | |
let nonwhite = matchend(getline('.'),'\S') | |
if nonwhite < 0 || col('.') <= nonwhite | |
return "\<Tab>" | |
else | |
let pos = virtcol('.') | |
let num = pos + &tabstop | |
let num = num - (num % &tabstop) - pos +1 | |
return repeat(" ",num) | |
endif | |
endif | |
endfunction | |
inoremap <Tab> <C-R>=VaryTabs()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment