How do I jump between function or section boundaries in Vim?
Answer
[[ and ]]
Explanation
[[ and ]] navigate between section boundaries — typically the start of the previous or next top-level block. In C-style languages, Vim looks for a { character in column 1, making these commands ideal for jumping between function definitions.
How it works
]]— jump forward to the next{in column 1 (start of next section/function)[[— jump backward to the previous{in column 1 (start of current/previous section)][— jump forward to the next}in column 1 (end of current section)[]— jump backward to the previous}in column 1 (end of previous section)
All four motions also work as operators — for example, d]] deletes from the cursor to the start of the next function.
Example
In a C file with this structure:
void foo() {
// ...
} <- [] lands here
void bar() { <- [[ and ]] land here
// ...
}
With cursor anywhere inside foo(), pressing ]] moves to the { opening bar().
Tips
- These motions respect
'sections'and'paragraphs'options for non-C filetypes - Use a count:
3]]jumps forward three section starts - Combine with operators:
y]]yanks from cursor to next function start - In Neovim, treesitter-based plugins like
nvim-treesitter-textobjectsprovide more reliable function navigation for any language