Can indent guides be displayed in Vim?

I am a longtime Vim user (3 or 4 years old) who recently started working with some deeply embedded code. This code is indented with spaces, not tabbed. I would like some kind of clean and non-distracting indentation sign to help keep track of which block of code I find when I look at something a lot in depth.

:set list 

Displays only tab and end line characters. I found one plugin (at the moment it seems that it cannot dig it out) that will highlight each indentation level in gradually darker colors, but this is visually unattractive. Ideally, I would like to see thin vertical lines at each indentation level. Many newfangled editors have this functionality, but I'm not ready yet to give up Vim.

Does anyone know how this can be achieved?

+42
highlighting vim plugins indentation
Jan 28 '10 at 22:02
source share
7 answers

NOTE. This answer was a bit late for the party, as well as the shameless plugin :)

Regardless, try the Indent-Guides.vim plugin . It was created to scratch my own itch due to the lack of indent guides in vim. I was tired of waiting for someone else to come and build it, so I just did it myself.

Features:

  • Can detect tab and space indent styles.
  • Automatically checks your color scheme and selects the appropriate colors (gVim only).
  • Highlight indent levels with alternating colors.
  • Full gVim support and basic support for Terminal Vim.
  • It seems to work on Windows gVim 7.3 (although there haven't been any extensive tests yet).
  • Custom size for indent guides, for example. skinny guides (only for soft tabs).
  • Customizable start level indentation.

Here are some screenshots of the plugin in action: hover and click .

+64
Feb 11 '11 at 10:58
source share

you can use the tabs to display the sweep guides and delete the tabs before saving the file:

 " use 4 spaces for tabs set tabstop=4 softtabstop=4 shiftwidth=4 " display indentation guides set list listchars=tab:❘-,trail:·,extends:»,precedes:«,nbsp:× " convert spaces to tabs when reading file autocmd! bufreadpost * set noexpandtab | retab! 4 " convert tabs to spaces before writing file autocmd! bufwritepre * set expandtab | retab! 4 " convert spaces to tabs after writing file (to show guides again) autocmd! bufwritepost * set noexpandtab | retab! 4 
+24
Jan 29 '10 at 5:09 on
source share

If you have entered the code with spaces, you can try the my plugin: https://github.com/Yggdroot/indentLine , it displays thin vertical but not thick vertical lines, as mentioned above. If you enclosed the code with the tab, simply :set list lcs=tab:\|\ (here is a space)

+22
Dec 06
source share

Points will be shown here indicating your level of indentation as you type. The points magically disappear when you leave the line.

 set list listchars=tab:»-,trail:·,extends:»,precedes 

eg:

 def test(): ....print('indentation level 1') 

Pretty cool, huh?

+15
Jan 29 '10 at 15:50
source share

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

+15
Jan 30 '10 at 5:31
source share

Try this VIM BlockHL plugin . It color encodes the indentation of each subsequent level in different ways.

EDIT: What are you using lanaguge? This plugin is designed for C-style languages.

+1
Jan 28 '10 at
source share

use the plugin Indent-Guides.vim and switch to using ig whenever you need it. Sometimes it can be annoying :)

+1
Jun 16 '15 at 5:14
source share



All Articles