2

Supposing we have some code:

var f = function(a) {
  var g = {"b" : "c",
           "m" : "n" // cursor is here
           "d" : "e",
           "h" : {
             "i" : "j",
             "k": "l"
             },
           "m" : {
             "n" : {"o":"p"}
             }
           } // want to get to here
}

What would be the most economic command in vi to navigate / jump to the closing bracket for the current scope.

Bear in mind:

  • we can't use % because we're not already on the opening brace.
  • we can't use [{ beacause it's not unmatched
  • we could use /{ and n, but this is cumbersome and requires more thinking than should be necessary.
mike3996
  • 17,047
  • 9
  • 64
  • 80
Rene Wooller
  • 1,107
  • 13
  • 22
  • I'm using the fwd example because it's harder in the snippet given, but moving backward to the opening braces would also be useful. – Rene Wooller Apr 29 '15 at 00:59

2 Answers2

2

?{ <ENTER> %
The first line of commands to go to the last opened {
Then % to find the matching brace

menakas
  • 376
  • 2
  • 7
0

In Vim, you can use ya{ which copies the text inside the nearest {} to the clipboard, but also moves the cursor to the opening {. You can then use % to jump to the corresponding ending brace.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285