3

Suppose I have a line of text of the form (123[456{789}abc]def) and the cursor is inside the curly braces. In sublime text, we can use ctrl-shift-m repeatedly to jump to highlighting 789, {789}, 456{789}abc, [456{789}abc], etc. Is there a way to duplicate this operation in vim?

EDIT: I know there are %v% and vib but they are different commands and not as fluid.

2
  • 2
    Have you tried the vim-expand-region plugin? Commented Sep 15, 2017 at 7:40
  • I think matchit's va%a%a% would be the logical sequence, but it doesn't work because a) matchit's a% is completely broken and b) matchit doesn't appear to support extension with repeated "a" objects. Perhaps a modern replacement to matchit is needed?
    – Mass
    Commented Sep 15, 2017 at 15:17

2 Answers 2

2

If I were on the first charater of the line I would do:

f7 to jump to inside the curly braces. vw to hilight 789 To contincously move outward I would do

vi]
va[
vi)
va)

But I am sure there is a better way.

0

Plugin vim-matchup

Mass has written the plugin match-up which allows you to press:

v a% a% a%

enter image description here enter image description here enter image description here enter image description here

However, there are many more plugins which provide a single command to expand over different types of brackets:

A cloc comparison if you look for a lightweight plugin enter image description here
(code size by number of source code and comment lines)

Please note plugins which depend on vim-textobj-user cannot be expanded, e.g. vim-textobj-anyblock. This is documented under :h textobj-user-known-issues (second item).

Your Answer

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

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