126

Is there a vim command to move the cursor to the parent bracket?

I have a configuration file like this one, and I want to go straight to the parent bracket. Is there a simple movement command to do this, or is there a way to combine commands to do what I want?

PARENT{ // I want to move my cursor here CHILD { stuff... } CHILD { stuff... } CHILD { stuff... } ... CHILD { stuff... } // my cursor is on this line CHILD { GRANDCHILD { more stuff } } CHILD { stuff... } } 

3 Answers 3

211

Yes. Do [{ in normal mode for that. It might not work for all languages though.

Many move commands are available at :help [.

Sign up to request clarification or add additional context in comments.

4 Comments

+1 for pointing out a feature I'd have already been using for years---if only I'd known about it. And ]} goes to the closing brace! What a bunch of keystrokes I've been wasting... `:-}
Hmm. I guess this only goes to the 'current' parent, though(?), so it doesn't exactly do what the OP desired. Is there a variant that pops all the way up or down?
Thansk! that helps me
using vim for 8 years still learning new things !
71

Also you can press % and it will show your open or close bracket

3 Comments

You must be on the close-brace for the % to work. It is more useful for brace matching rather than navigation.
@user31986 I think you are wrong there: it works for opening and closing brackets. Actually, it does not only work for the brackets ([{}]) but also for C-type comments /*...*/
@user31986 was essentially correct, though: the question asks to move from the inside of some structure to some parent brace, while this answer is about going from one symbol (parenthesis, bracket or brace) to the matching one. This is related, but is not an answer to the question.
12

It looks like [[ does what you want. And ][ moves to the bottom-most brace. (With many thanks to @Benoit for cluing me in that this might be possible...)

1 Comment

'[[' & '][' work only when the opening brace is the first char on the line, not when it is as in the question. "PARENT{ "

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.