DEV Community

Cover image for 3 Vim commands for blazingly fast navigation between brackets ⚡

3 Vim commands for blazingly fast navigation between brackets ⚡

Max Shen on February 24, 2024

There are often lots of brackets within a programming file. Therefore the efficiency of navigating between them becomes crucial for the overall pro...
Collapse
 
mirzalazuardi profile image
Mirzalazuardi Hermawan

Thats why i use vim

Collapse
 
jonathan_leffler_336f14e5 profile image
Jonathan Leffler • Edited

The usefulness of [[ and ]] depends on the coding conventions you work with. In C, K&R style places the opening brace of a function at the start of a line. If you follow that part of K&R style, then [[ and ]] are useful for jumping to the previous/next function (and a repeat count works for jumping N functions). If you follow the { at the end of a line, even on function definitions, then the [[ and ]] operations are much less useful.

If you're working in a language with different conventions, especially if the conventions are enforced by a formatter (gofmt, rustfmt, etc), then they aren't as helpful. You may be reduced to using []% and ][% — jump to the end of the function and bounce back to the start — and heaven help you if you have stray unmatched curly braces in the function.

Thanks for the article. I wasn't aware of [] or ][, nor of ]) or [(, nor of [{ or ]}.

Collapse
 
sytranvn profile image
Sy Tran Dung

Python dev sit in corner.

Collapse
 
dairdev profile image
Dennis

Great plugins to improve handling brackets are:
Old but good, this Tim Pope's plugin: github.com/tpope/vim-surround
If you are in the Neovim world using Lua plugins: github.com/kylechui/nvim-surround

Collapse
 
gokayburuc profile image
gokayburuc.dev

Year 2024 and which-key.nvim is still the best plugin.

Which-key.nvim

Collapse
 
ibconcept profile image
william maina

Honestly for me the % is not working, please advice