Skip to content

Instantly share code, notes, and snippets.

@graywh
Created November 16, 2012 21:25
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 graywh/4091066 to your computer and use it in GitHub Desktop.
Save graywh/4091066 to your computer and use it in GitHub Desktop.
Insert tabs at beginning of line, spaces afterward
function! TabOrSpace()
let text = strpart(getline('.'), 0, col('.')-1)
if text =~ '^\t*$'
return "\<C-v>\<Tab>"
else
let l = strdisplaywidth(text)
let n = float2nr(floor(l / &l:softtabstop) + 1) * &l:softtabstop
return repeat(' ', n - l)
endif
endfunction
imap <expr> <Tab> TabOrSpace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment