In vim, there are handy commands to move to the nearest enclosing left or right curly brace ([{ and ]} respectively).
However, typically when navigating JSON files, it is equally useful to be able to jump to the nearest enclosing square bracket. Yet, in the long time I have been wishing for this command, I haven't found it, either built into vim or provided by a plugin. Is it there somewhere?
How about va[ when you are inside the []. This will visually highlight the enclosed []. Esc takes the cursor on the closing ].
To go to opening [, Press %.
Or to shorten it, map it to a key of choice, eg to F2 and save it in vimrc
nnoremap <F2> va[<esc>%
I have the following two mappings in my vimrc
nnoremap ]b :call searchpair('\[','','\]')<cr>
nnoremap [b :call searchpair('\[','','\]','b')<cr>
compare also :h searchpair. You can change ']b' and '[b' to whatever you like of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With