Reputation: 603
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?
Upvotes: 2
Views: 2429
Reputation: 171
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.
Upvotes: 2
Reputation: 10391
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>%
Upvotes: 8