6

I understand that f jumps to the first matching character, and t jumps to one character just before the first matching character

For example, given the string VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, I would like to change it to VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL. with the caret on V I should press 4f_lct_SRC to achieve that

But I'm wondering if there is a key that allows me to jump to one character just after the first matching character, so I can omit the l offset, (which frankly trips me up sometimes) and turn the sequence into 4 %SOMETHING% _ct_SRC

I understand that this can be accomplished by macros (or in this specific example circumvented by a substitution), but I'm wondering if this functionality exists out of the box

1

2 Answers 2

4

You can use search, e.g. /_DST/s+ to move the cursor to the D of the DST part. The part after the search pattern is the offset, so s+ moves the cursor 1 character to the right of the start of the pattern, while, e.g. e-2 would move the cursor 2 character to the left of the end of the pattern.

See the help at :h search-offset

4
  • 1
    I actually didn't know about search offsets. That would help a lot, neat. However in the general case I would need to look for something after a _, and cannot rely on a string like DST existing all the time. A solution would ideally require only knowledge of _. But still, search offsets, looks useful.
    – Wagk
    Commented Apr 21, 2017 at 10:18
  • 1
    You can also combine this with a count, e.g. 4/_/s+ Commented Apr 21, 2017 at 10:21
  • 1
    Is there a default keybind that does this for me though? I'd prefer to not have to append a /s+ or map a binding.
    – Wagk
    Commented Apr 21, 2017 at 10:25
  • you would have to map this to a new key combination. Commented Apr 21, 2017 at 10:45
2

Maybe I don't understand your question, but why are you not using fD? That puts you right on the D.

Furthermore, you can define underline as a keyword via set iskeyword-=_. In your situation, this allows the change via cw. That is quite handy.

So in total just fDcwSCR.

Last but not least you can roll out the big guns and employ plugins like CamelCaseMotion or vim-sneak.

4
  • 1
    I can't assume that what comes after _ will always be a D. I can only assume that there is some text after a _ that I want to edit
    – Wagk
    Commented Apr 22, 2017 at 12:15
  • No, of course not. That is just meant as a specific answer to your specific example. And, if this is something you need a lot, you should have a look at those movement plugins; they may well suite your needs.
    – mike
    Commented Apr 22, 2017 at 12:31
  • @Wagk, with vim-sneak, you can do fDSct_SRC, which is one character less than your original solution.
    – jdhao
    Commented May 31, 2019 at 2:48
  • set iskeyword-=_ has downsides Commented Jun 16 at 11:11

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.