Probably the most effective solution would be to “draw” the indentation guides using matching highlighting. To see how this helps, take a look at this example:
:match Search /\%(\_^\s*\)\@<=\%(\%1v\|\%5v\|\%9v\)\s/
It selects (using the search highlight group, you can use any other, of course) the first, fifth, ninth (and this can be continued) virtual column occupied by a space character, preceding nothing but a space from the beginning of the line. Thus, this leads to the allocation of four-position indents for three levels in depth.
To generalize this idea, it remains only to create such a pattern of the ones mentioned above in accordance with the current buffer textwidth and shiftwidth (for processing deeper indents and the corresponding indent width). This task can be simply automated, as shown in the function below.
function! ToggleIndentGuides() if exists('b:indent_guides') call matchdelete(b:indent_guides) unlet b:indent_guides else let pos = range(1, &l:textwidth, &l:shiftwidth) call map(pos, '"\\%" . v:val . "v"') let pat = '\%(\_^\s*\)\@<=\%(' . join(pos, '\|') . '\)\s' let b:indent_guides = matchadd('CursorLine', pat) endif endfunction
Each time you need indentation guides in the buffer, you can enable it :call ToggleIndentGuides() . Of course, you can change the selection group (or create a special one for use only in indentation guides), configure convenient display 1 for this and / or call it from autocmd for some file types.
1 Retreat Guides Extracting Configuration from My .vimrc File: https://gist.github.com/734422
ib. Jan 30 '10 at 5:31 2010-01-30 05:31
source share