Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code: jump to next occurrence of character x

In Vim, you can press fx and Fx to move to the next and previous occurrence of x on the same line:

**fx** - jump to next occurrence of character x
**Fx** - jump to previous occurence of character x

source: https://vim.rtorr.com/

I don't wish to use a vim emulator in VS Code, I instead would like to bind Ctrl+f to forward search and Ctrl+b for backwards search.

How can I do that?

like image 273
WickedJargon Avatar asked Oct 12 '25 00:10

WickedJargon


2 Answers

I just posted an extension (I'm pretty sure you can't do it without an extension) that does what you want: Jump and Select

It does a little more than you want in case other people would like the selection option. You can bind any keybinding to the commands you want. The following demo uses Alt+f for forward and Alt+b for backward.

Jump and Select demo

Note that the key you want to go to is not displayed. And you don't have to hit Enter to trigger the move - it just goes there immediately. And it works with multiple cursors.

Also, I am not familiar with vim. If you go back to some designated previous character, should the cursor end up before or after that character? Right now it goes to that character (so the cursor is after it) but it is easy for me to make to change that behaviour in the extension. Just let me know.

multiMode jumping

like image 173
Mark Avatar answered Oct 15 '25 09:10

Mark


In VSCode, "find next" is performed by Ctrl+G (Cmd in MacOS) and "find previous" by Ctrl+Shift+G.

You can edit the keyboard shortcuts by going to Code > Preferences > Keyboard Shortcuts and looking for both "Find Next" and "Find Previous", and hovering over the keybinding to edit it to your preference.

enter image description here

like image 22
Guillermo Brachetta Avatar answered Oct 15 '25 09:10

Guillermo Brachetta