Jeff Erickson
Jeff Erickson

Reputation: 177

How to quickly navigate function arg lists in vim

I have the following function definition:

def test(these, are=0, args=1):
    pass

I want to find a quick and intuitive way to hop between each argument.

For example, pressing w/b is too slow because it will hit the commas, but even worse it is it will hit the =. W/B works great except with that first argument because test(these is a "WORD".

Is there an existing way to navigate this list that works the same for all arguments, or is there a common modification to do this? For example, can I redefine what a WORD is and make the (/) break up a WORD? I can't think of a good example of when I would have a legitimate WORD with a paren right in the middle.

Upvotes: 0

Views: 724

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172688

The big complication with argument lists is complex expressions and nested function calls (e.g. foo(1, bar(2, 3), 4)). To handle those, at least some basic parsing is necessary; simple pattern matching (as can be done with built-in commands) won't do.

I personally use a combination of basic Vim commands, tailored to the current situation (i.e. w / W / f{char}), and the following plugins:

  • sideways has mappings to jump to next / previous arguments, to move arguments around, and corresponding text objects
  • fieldtrip builds on top of sideways and offers a submode, where individual keypresses can then be used to jump / move

Upvotes: 1

SergioAraujo
SergioAraujo

Reputation: 11820

Just try using ft f0 or f1 to see if these jumps can help you.

Upvotes: 0

Related Questions