Reputation: 211
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?
Upvotes: 2
Views: 6216
Reputation: 181359
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.
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.
Upvotes: 6
Reputation: 4775
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.
Upvotes: 3