2

Suppose my cursor is at the beginning of the line of code:

def f(a, b, c, d, e):

If I want to change inside the parenthesis using the text object command ci(, I need to first navigate to some position in the parenthesis.

I would like it if I could just jump to the first relevant text object after my cursor when I type ci( (and analogous commands). How would I configure vim to do this?

1
  • 2
    This is not a duplicate but this question is strongly related because it explains why ci( and ci" behave differently.
    – statox
    Nov 15, 2018 at 9:15

1 Answer 1

6

The wellle/targets.vim plugin should do what you're looking for (and much more). This allows you to explicitly tell vim to go to the next parenthesis (with cin(, n for next parenthesis), or the last parenthesis (with cil(), but it also overrides the default so that you jump to the next or last if you don't specify. From the README:

  • This overrides Vim's default text object to allow seeking for the next pair in the current line to the right or left when the cursor is not inside a pair. This behavior is similar to Vim's seeking behavior of di' when not inside of quotes, but it works both ways.

...

Next and Last Pair

in( an( In( An( il( al( Il( Al( ...

Work directly on distant pairs without moving there separately.

All the above pair text objects can be shifted to the next pair by including the letter n. The command in) selects inside of the next pair. Use the letter l instead to work on the previous (last) pair. Uses a count to skip multiple pairs. Skipping works over multiple lines.

See our Cheat Sheet for two charts summarizing all pair mappings.

This also adds the "argument" text object. For example, dana to delete the next argument. And many other text objects as well.

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.