How to show a vertical rule at the beginning of the current line?

I am looking for a way in vim to easily visualize various levels of python indentation. This would help if there was always a vertical rule at the beginning of the current line. That way, I can check the code to see where the current block ends. Are there any plugins that do this?

+4
source share
5 answers

You can simply emulate the indent guides. In my opinion, it is easier and more efficient. Please take a look at my answer to the question about indentation pointers .

+5
source

The first thing that comes to mind is that you can use a plugin that implements code folding .

Below is an example with examples (scroll down to "Code folding"), in which it is recommended to use the "Effective python forger" for vim .

screenshot http://dancingpenguinsoflight.com/wp-content/uploads/2009/02/folded_functions.png

+1
source

in vim (no plugins required):

: set list

will display tabs as '^ I' and EOL as '$' by default.

from

: set lcs = tab: →

you set '^ I' to '>' (for more on this, see: help listchars).

I'm not sure, but there should be another option for setting the tab width.

also you can set

: install autoindent

for python

0
source

I think the command you are looking for is "colorcolumn", it is new to vim 7.2 or 7.3, I think.

Maybe you can do something with the CursorMoved auto command

autocmd CursorMovedI * set colorcolumn=match(getline("."),"\S") 

You may have to play with this using intermediate variables, etc.

What would it do (if it is properly buried inside the function), one vertical line is placed in the initial character of the current line. It may be convenient, but you probably only need to put a switch.

EDIT: This turns out to be a little more complicated than I originally thought. Basically you need to eliminate the effect of literal tabs (if they appear in your file)

 autocmd CursorMoved * let &colorcolumn=matchend(substitute(getline("."),'\t',repeat(" ",&ts),'g'),"\\S") 

When I first brought it together, I realized that it was stupid, but, playing with it for a few minutes, I like the effect.

Please note that you may or may not want to have a version of CursorMovedI.

0
source

You can define your own syntax elements (or use matches) for yourself. Quick and dirty solution:

 let colors=["red", "white", "yellow", "green", "blue"] let matchids=[] for level in range(1, len(colors)) execute "hi IndentLevel".level." ctermbg=".colors[level-1]." guibg=".colors[level-1] call add(matchids, matchadd('IndentLevel'.level, '^ '.repeat(' ', level-1).'\zs ')) endfor 

The first five levels of indentation with different colors will be highlighted here.

To disable:

 while !empty(matchids) call matchdelete(remove(matchids, 0)) endwhile 
0
source

All Articles