4

How can we have a vertical line shown between the braces in vim editor. It is helpful when I am writing C code.

Upto now, while using vim editor, if i want to know the position of the closing brace, i do following:

  1. In normal mode, I take the cursor to opeining brace { and then press % which take the cursor to closing }.

  2. And then (try) to remember the line numbers of opening and closing brace.

But when I do this I often forget the line numbers of opening and closing braces. Plus, many times the brace pairs are nested which makes it more confusing to remember.

So I want to have a vertical line drawn between the braces, so that I can do the following:

  1. In normal mode, take the cursor to open { and press j or k (or even % or any other motion command) to navigate through the file. But with an added line on the left side so that i can know which block I am in.

So, if the code is indented properly, then by looking at the line on the left side I will always have a track of which block I am in. And can use j and k (or any other motion command) without having to remember the line number of opening and closing brace.

How can we do this in vim ?

Update: Got the answer here Is it possible to display Indentation guides in Vim? .

Community
  • 1
  • 1
sps
  • 2,720
  • 2
  • 19
  • 38
  • 1
    Have you tried setting [marks](http://vimdoc.sourceforge.net/htmldoc/motion.html#mark-motions) on the open/close braces? You might also look into the [object motions](http://vimdoc.sourceforge.net/htmldoc/motion.html#object-motions). – Kevin May 31 '15 at 02:25
  • @kevin Thanks, but does mark draw the line ? I want to have a line on left side. The link you forwarded was difficult to understand, so i thought to ask you this before trying to go through it. – sps May 31 '15 at 02:47
  • Why do you need to remember the position ? just test if you press `][` or `]]` you will move to the `}` or `{` . As your code is indent why draw a vertical line, the code does it, doesn't it ? – Ôrel May 31 '15 at 03:40
  • @Orel Yea the indented code makes it inherently indented, but I get confused once I move to next pages. I cannot remember `what level of indentation means which block`. So I wanted some sort of line to help me. Found the solution for now (as I only use tab for indentation). This is the command `:set list lcs=tab:\|\ ` – sps May 31 '15 at 03:53

1 Answers1

11

The indentLine plugin can help you indentLine plugins https://github.com/Yggdroot/indentLine (new location)

Josh Beauregard
  • 2,498
  • 2
  • 20
  • 37
Ôrel
  • 7,044
  • 3
  • 27
  • 46