0

I often navigate to the next occurrence of the current non-paren character. For example,

`HTTP GET www.example.com/example/com` is an example URL.

When the cursor is at the beginning of the line at the ` character, it is useful to jump the the next occurrence of the `.

This can be achieved by f` (How to jump to a specific character in vim?), but I winder if I'm missing any single-character shortcut. If not, I'd be happy to know what's the right way to map such a key binding please.

How do I navigate to the next occurrence of the current character with s single keystroke?

1

It's tricky and working only for predefined pair of characters, but you can leverage matchit plugin, found on SO:

:let b:match_words='`\<:\>`'

Then you can alternate with %, though it may have caveats (see :help b:match_words).

  • Thanks, but I'm looking for a more general solution. I assume we can keybind it somewhow. – Adam Matan Aug 20 '17 at 13:22
  • I guess you will need at least 2 key strokes to trigger the mapping and specify a character. There is probably a plugin for your use case, (not) like those which jump to a location specified by 2 characters: vim-seek and vim-sneak. – LEI Aug 20 '17 at 22:23
  • It could easily be mapped to a single keystroke. See the two similar questions I linked to in the comment to the question. – Herb Wolfe Aug 21 '17 at 0:52
  • Nice catch, I didn't think of yl:normal f<C-R>"<CR> which effectively copies the character under the cursor and pastes it after f. – LEI Aug 21 '17 at 5:57

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.