How do I quickly jump between function definitions or top-level blocks in a source file?
Answer
[[
Explanation
The [[ and ]] commands navigate between top-level code blocks — specifically, lines where { appears in column 1. In C, Go, shell scripts, and similar languages, this corresponds to the start of function definitions. Their siblings [] and ][ jump to closing braces in column 1, letting you navigate the full structure of a file without search.
How it works
| Command | Jumps to |
|---|---|
[[ |
Previous { in column 1 (start of previous function/block) |
]] |
Next { in column 1 (start of next function/block) |
[] |
Previous } in column 1 (end of previous function/block) |
][ |
Next } in column 1 (end of current function/block) |
All four accept a count prefix: 3[[ jumps to the start of the function 3 levels back.
Example
In a C file:
void foo() {
...
} <- [] lands here
<- [[ jumps over this
void bar() { <- [[ lands here (column-1 {)
...
} <- ][ lands here
void baz() { <- ]] lands here
Tips
- Works well in combination with
v]]to visually select to the next function - In Python or Ruby (no
{), these commands fall back to moving by section marks or may not work — use[mand]minstead to jump by methods - Add to your workflow:
d]]ory]]to delete/yank to the next function start