Skip to content

Instantly share code, notes, and snippets.

@kshenoy
Last active December 17, 2015 19:39
Show Gist options
  • Save kshenoy/5661828 to your computer and use it in GitHub Desktop.
Save kshenoy/5661828 to your computer and use it in GitHub Desktop.
Insert tabs at start of line and spaces elsewhere
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