8

I read the solution answered in https://stackoverflow.com/questions/11037825/vim-get-out-of-parenthesis-brackets-etc. That is nothing but command A that takes away you in the end of line.

But, my requirement is something different. Suppose I have a file containing -
x = (3+5)/(2+1);
When cursor is on + I want to move the cursor on / or first ), but not on ;(You can consider 'after the character' instead of 'on the character' ).

2
  • 1
    something like this: nnoremap ,f /[)/]<cr>? Feb 15, 2018 at 9:06
  • @ChristianBrabandt Yes, something similar this. But, the parenthesis are may be different so I have to check whether I am in () or {} or [] or <>(although it is not parenthesis).
    – alhelal
    Feb 15, 2018 at 9:13

2 Answers 2

23

I'm not 100% clear if this is what you're asking, but I think you might be looking for:

])

This jumps to the nearest enclosing ). So if your cursor was on the / in the below:

(2 / (3 + 5) * 9) 
   ^

It would skip past the first ) and jump to here:

(2 / (3 + 5) * 9)
                ^

Alternatively, for your more simple case, %% would also work. The first % jumps to the opening (, and the second jumps to its counterpart, the closing ).

See:

  • :help ])
  • :help %
3
  • 1
    ]} ]) [{ [( work but [[ and ]] don't work.
    – alhelal
    Feb 15, 2018 at 9:45
  • 2
    @alhelal [[ and ]] do something different: see :h ]]
    – Rich
    Feb 15, 2018 at 9:49
  • What would you do to make it work with ]]? May 28, 2022 at 10:47
2

My plugin match-up provides the mappings ]% and [% which is like a delimiter-agnostic version of ])/]} to go to either element of a surrounding matching pair. Since it uses the symbols listed in matchpairs, it works for ()/{}/[] by default and will work for < and > if matchpairs contains <:>.

Filetypes can also specify more advanced matching pairs (e.g., if/endif in vimscript), similar to the plugin matchit which is distributed with vim (except matchit seems to be unmaintained and these mappings don't work).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.