yankolo
yankolo

Reputation: 531

Vim: % command doesn't move to first parenthesis

I am reading the vim manual. I am having an unexpected result using the % command.

Here is a quote from the manual:

When the cursor is not on a useful character, "%" will search forward to find one. Thus if the cursor is at the start of the line of the previous example, "%" will search forward and find the first "(". Then it moves to its match:

  if (a == (b * c) / d)
  ---+---------------->
         %

However, when I repeat the same thing (placing the cursor at the start of the line) and press %, the cursor moves the last ) parenthesis instead.

I didn't configure vim, I am using the default settings. I am wondering if my vim is not configured well. Is there a way to configure vim for it to move the cursor the first parenthesis similar to how it is described in the manual?

I am using gVim on Windows.

Upvotes: 2

Views: 126

Answers (2)

mattb
mattb

Reputation: 3062

Also you can use f( to move the cursor to the first open parenthesis (if it's not on the same line, you can use search for it like /( just as easily). This is helpful since you could do something like df( (or d/( to target a different line) to delete everything up to and including the open parenthesis. Whereas relying on a double press of % wouldn't allow that.

Upvotes: 3

Blondberg
Blondberg

Reputation: 121

"it moves to its match", which means that it will move to the matching paranthesis of the one it found (in this case the closing paranthesis). So it does what it should.

To get back to the first paranthesis you will need to press '%' again!

Upvotes: 5

Related Questions