Skip to content

Instantly share code, notes, and snippets.

@simlrh
Created February 6, 2017 18:06
Show Gist options
  • Save simlrh/7c64840c4719bf86b98f5a2622c15b4e to your computer and use it in GitHub Desktop.
Save simlrh/7c64840c4719bf86b98f5a2622c15b4e to your computer and use it in GitHub Desktop.
Indentation functions for vim
"------------------------------------------------------------
" Indentation options {{{1
"
let g:mytabcolumns = 4
set noexpandtab
set softtabstop=0
set shiftwidth=4
set tabstop=4
function! ToggleTabMode()
if &expandtab
set noexpandtab
set softtabstop=0
echom "Using tabs for indentation"
else
set expandtab
let &softtabstop=g:mytabcolumns
echom "Using spaces for indentation"
endif
endfunction
function! TabColumns(n)
let g:mytabcolums=a:n
let &tabstop=a:n
let &shiftwidth=a:n
if &expandtab
let &softtabstop=a:n
endif
endfunction
function! HighlightIndentation()
call clearmatches()
if &expandtab
echom "Using spaces for indentation"
call matchadd("Error", "^\t\t*")
else
echom "Using tabs for indentation"
call matchadd("Error", "^ *")
endif
endfunction
command! -nargs=1 Spaces call TabColumns(<f-args>)
nnoremap <Leader>j<Space> :Spaces
nnoremap <Leader><Tab> :call ToggleTabMode()<cr>
nnoremap <Leader><Space> :call HighlightIndentation()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment