How do I jump to the nearest unmatched opening parenthesis or bracket above the cursor?
Answer
[( / [{ / [{
Explanation
The [( and [{ motions jump backward to the nearest unmatched opening parenthesis or curly brace. Their counterparts ]) and ]} jump forward to the nearest unmatched closing delimiter. These are invaluable for navigating code where you need to find which block or function call you are currently inside.
The motions
| Motion | Jumps to |
|---|---|
[( |
Previous unmatched ( |
[{ |
Previous unmatched { |
]) |
Next unmatched ) |
]} |
Next unmatched } |
"Unmatched" means the delimiter does not have a matching pair between it and the cursor.
Example
if (x > 0) {
while (y < 10) {
doSomething(x, y);
// cursor is here |
}
}
With cursor on the comment line:
[(jumps to the(ofwhile (y < 10)[{jumps to the{ofwhile2[{jumps to the{ofif2[(jumps to the(ofif (x > 0)
Tips
- Works as a motion with operators:
d[(deletes from cursor back to the unmatched(;y[{yanks from cursor back to the unmatched{ - Accepts a count:
3[(finds the third unmatched(outward %jumps between matched pairs;[(and])find UNmatched pairs — they solve different problems- For C/C++,
[mand]mjump to method/function boundaries (similar idea but language-aware) - These motions work in any language — anywhere that uses
()or{}as delimiters