public
Last active

Vim Indentation Guides Emulation

  • Download Gist
gistfile1.vim
VimL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
nmap <silent> <leader><bar> :call ToggleIndentGuidesTabs()<cr>
nmap <silent> <leader><bslash> :call ToggleIndentGuidesSpaces()<cr>
 
function! ToggleIndentGuidesTabs()
if exists('b:iguides_tabs')
setlocal nolist
let &l:listchars = b:iguides_tabs
unlet b:iguides_tabs
else
let b:iguides_tabs = &l:listchars
setlocal listchars=tab:┆\ "protect the space
setlocal list
endif
endfunction
 
function! ToggleIndentGuidesSpaces()
if exists('b:iguides_spaces')
call matchdelete(b:iguides_spaces)
unlet b:iguides_spaces
else
let pos = range(1, &l:textwidth, &l:shiftwidth)
call map(pos, '"\\%" . v:val . "v"')
let pat = '\%(\_^\s*\)\@<=\%(' . join(pos, '\|') . '\)\s'
let b:iguides_spaces = matchadd('CursorLine', pat)
endif
endfunction

Could you show a screenshot about it?

@zhouzhuojie: Here are two: one for tabs and one for spaces.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.