0

Suppose I have a string like

takeThisAsAFunction(someParameter, someNestedFn(furtherNesting(foo, oneMoreNesting())), someText);
      ^                                                                              !  

Lets's say I have cursor at location ^, and I want to go to second last ), pointed by location !, how can I jump directly to that. Currently I do

$2F)

Is there any better way?

7
  • 1
    if you knew the function name, /some<CR>%, but that's not necessarily "faster", just easier to think about (find the close paren of the function call starting with some vs. second-to-last close paren). I think you've expressed the latter as clearly as possible
    – D. Ben Knoble
    Jul 19 '20 at 1:39
  • I mapped % to <c-g>, hence I'd do %h%l% but I'm not sure it's 'better'. Besides, $2F( does not jump to the character you mention in your example, which one is the one you want?
    – Biggybi
    Jul 19 '20 at 8:47
  • Oopsie, It was a typo, I will edit it in the question. I wanted to write $2F), I hope you could understand the intent.
    – CodeTalker
    Jul 19 '20 at 10:23
  • Well, this is still not exact. F) would put you on your marker, not 2F), that's why I wasn't sure what you meant. Sorry if I sound picky, I just want to make sure we're on the same page here.
    – Biggybi
    Jul 19 '20 at 10:57
  • @D.BenKnoble <c-g> is % for me!
    – Biggybi
    Jul 19 '20 at 17:18
1

The "problem" with 2F( is the 2: you need to count, which is easy in some case, but can be troublesome most of the time.

I see several brainless ways of doing what you intend:

  • %: %h%l%h%l...

the percent sign jumps to the symbol that matches the one under the cursor (e.g. closing/opening parenthesis), or the first closing symbol after your cursor. Use l and h to go a level inner and get closer to your search

  • /: /function_name<cr>%

As pointed by DBK's comment, same idea as above, if you know the name of the function

  • f: f);;;...

jump to the next ), then use ; to repeat. , goes backwards.

  • /: /(,

Using a unique sequence in search is a fast way to jump anywhere in a file

  • B: $Bj

B jumps to the end of the previous WORD (i.e., sequence of characters delimited by white spaces), that fits your example perfectly.

  • W: WWWj

Same as above, but jumping forwards by WORD instead of backwards.

Final thoughts:

Always try to get as close as you can and avoid using h and l, but don't force yourself not to use them. h and l are perfectly OK when you're right next to the character you're aiming at.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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