Question

Is there a Vim shortcut for jumping to the argument list of the current function? I often find myself needing to mess with the argument list of a function, and it's kind of annoying to have to do ?def or ?function or 10k or what-have-you until I finally get to it, then /( or t( or 5e to get to the right position in the argument list, and so on. It would be great if I could just hit ,a for example and instantly get put into insert mode at the end/beginning of the argument list.

Possible approaches:

  • Folding
  • Tag support (ctags)

Also, I'm using Python, so solutions based on curly braces unfortunately won't work.

If no such shortcut exists, I'll just write one and post it here as an answer. :-)

Was it helpful?

Solution

The fool proof way of getting to the begining of a function is to use [[. So you use

map ,a ma[[kf(a

so it can take you to the function definition, search for the first occurance of "(" and then put you in the insert mode.

OTHER TIPS

Disclaimer, I don't know Python, I assume a Python function can be identified by "function" or "def" from your question. Just change the regex in consequence.

May be something like:

   :nnoremap <buffer> [m :call search('def\|function', 'b')<cr>f(

?

NB:

  • I have used search() in order to not mess up the search history ; searchpair() may be a better choice as it will only jump to the definition of the function we are within, instead of the previous function.
  • As this is intended to work with Python only, I use <buffer> in order to not mess up the key-binding in non-Python files; this mapping is best defined in a python ftplugin.

HTH,

map ,a ma[{F(a

Hit ,a to go to the argument list, then `a to return to where you were when you invoked ,a. Caveat: [{ jumps back to the last unmatched { character, so if you're inside a loop or other control structure, it will take you to the beginning of that, instead.

I don't know of a way to get to the beginning of the function in a fool-proof way. If you're consistent about your tabbing, you may be able to do something like this:

map ,a ma?function :nohlf(a

where, if you don't use a single tab before you define your functions, you'd change to appropriate value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top