How do you avoid key binding collisions between VS Code and vscodevim?
Asked Answered
F

6

21

I have some shoulder pain that I am trying to get rid of by using vscodevim.

My biggest problem with vscodevim so far is that is sometimes collides with VS code shortcuts. For example I often save all my files with Ctrl+K S. But with vscodevim enables, instead that key combination does something else.

I feel tired about the prospect of having to build a configuration with my own key VS Code key bindings, that don't conflict with vsvim. I hope there is a better solution.

So I ask you, my better knowing colleagues, how do you solve this problem?

Flocculent answered 16/6, 2020 at 9:55 Comment(2)
I simply hit the alt key. This puts the focus on the menu bar so that only VS Code shortcuts would work. After that I can put the focus back on the buffer using Ctrl+1 or console using Ctrl + `Longitude
@Longitude To be honest I think your comment is worth an answer, I personally find that the best way to be able to dive in vim at my own pace and at the same time be fast when I need to, not to mention I need to be able to stuff that strictly pertain to the editor that I'm not sure would be possible to do using just the extension, such as Ctrl + B to show the workspace tree etc.Thereunder
W
19

There is no easy way out for avoiding conflicts between vscode shortcut and vscodevim bindings. I suggest you to use vim keybindings instead of vscode shortcuts wherever possible. Vscodevim can prove to be a good gateway to vim provided you are open to relearning how you use vscode.

Instead of building your own configuration that doesn't collide with vscodevim you could redirect the effort in finding a way to do the same thing in vim. You can search web or use vim help.

Vim help is really comprehensive and easy to read. If you have vim installed you can use :help or :h followed by a specific subject, for example if you need to read about navigation type :h navigation.

Now you have two choices and I will try to use example you provided i.e. saving a file :

  1. Use bindings available for saving file in vim.

    Vim provides so many shortcuts just for saving and quitting files, in vim try :help write and :help quit to know more. Many of those shortcuts works in vscodevim too.

    To save file :

    • :w to save a single file

    • :wa to write all buffers (in vscode all modified files).

  2. Remove the bindings from vscodevim and use vscode shortcut.

    You can delegate the key combination back to vscode. I suggest you do this only if there is any vscode shortcut that is absolutely necessary for you and it conflicts with vscodevim as doing this may result in some related vim bindings to not work. To know what Ctrl+k does in vim type :h ctrl-k in vim.

    If you want to use Ctrl+K S for saving file do following:

    • Open vscode settings and search for vim handlekeys or directly open vscode's settings.json:

    • add following "vim.handleKeys": {"<C-k>": false}

I don't know if this a better solution but I was in your situation and tried different ways to solve it. Finally I found it was much easier to use vim keybindings than trying to coerce vscodevim.

Willetta answered 16/6, 2020 at 16:49 Comment(8)
I didn't expect solution 2 to work, but it did. (I expected to have to put something like "<C-k> s": false)Stasny
I've used vim for over 12 years and there's a lot of cases where the IDE shortcut is better than the vim shortcut - making binary statements that vim is definitely the better choice is always a bit suspect. For example ctrl p to open file has a lot better integration with the IDE than vim. Ctrl+f for the integrated find widget is better than using slash and having to manually escape characters.Singlehanded
@Singlehanded Have I said that vim shortcut is definitely the best option? I understand your concern. I didn't mean to imply that Vim shortcuts are the absolute best option. Both options have their merits, and the best choice depends on the specific situation. Hence, there are two choices given in the answer.Willetta
You've just stated: "Instead of building your own configuration that doesn't collide with vscodevim you could redirect the effort in finding a way to do the same thing in vim. You can search web or use vim help." If they applied that logic they'd end up using forward slash in place of the ctrl+f functionality. The vim way of doing this is worse - as you have to escape characters and isn't as well integrated. Sounds to me like you've just picked up vim and now think it's the best thing in the world. It is, but only for certain cases.Singlehanded
You've also stated "There is no easy way out for avoiding conflicts between vscode shortcut and vscodevim bindings." there is - it's in the docs for vscodevim. Not sure why you've got 20 upvotes.Singlehanded
"There is no easy way out for avoiding conflicts between vscode shortcut and vscodevim bindings." because you have to use either IDE shortcuts or vim keybinding and hence two choice was given.Willetta
"Instead of building your own configuration that doesn't collide with vscodevim you could redirect the effort in finding a way to do the same thing in vim. You can search web or use vim help." Should I not describe how to find help If someone wants to use first choice of the answer?Willetta
"Sounds to me like you've just picked up vim and now think it's the best thing in the world." Thanks for your kind words but I assure you that I don't think vim is solution to everything.Willetta
C
8

I installed "vscode neovim" instead of "vim". Open the vscode setting, you can search "vscode-neovim: Use ctrl keys for insert Mode", disable it. So you can use "ctrl k+ ctrl c" to add a line comment in insert mode. Also other vscode "ctrl" keys could be used in this mode.

disable use Ctrl keys in insert mode

Caterwaul answered 7/6, 2022 at 15:15 Comment(0)
E
6

I set up a "toggleVim" keybinding, like so: https://mcmap.net/q/323341/-how-to-toggle-between-vim-emulation-and-no-vim-emulation-when-the-vscodevim-extension-is-installed

When I want to use a hotkey that clashes with vim, I just turn off vim.

Endermic answered 26/1, 2021 at 23:58 Comment(1)
I often forget to toggle it back on. If someone knows a way to automatically turn it back on once focus reenters the buffer, please let me know.Endermic
F
3

There's a setting you can disable in the vscodevim extension settings (it's on by default): enable ctrl keys

Fleabag answered 8/2 at 20:16 Comment(0)
S
2

To prevent vim from handling certain shortcuts the best approach is to edit your settings.json (Ctrl+P - settings.json)

For example I have a section in my settings.json as follows:

"vim.handleKeys": {
    "<C-s>": false,
    "<C-f>": false,
    "<C-p>": false,
    "<C-v>": false,
    "<C-c>": false
}

This is using vim keybinding syntax; C-v is Ctrl+v, C-c is Ctrl+c etc. Save and then restart Visual Studio Code.

This is documented in the documentation for the vscodevim extension.

Singlehanded answered 25/4 at 14:22 Comment(0)
T
0

Like some people said you can disable it in the extension vscode-neovim in the setting Ctrl Keys For Insert Mode but I think it is worth to mention that you can keep combinations active:

Screenshot of setting vscode-neovim.ctrlKeysForInsertMode

You can see in the image that I have activated a few ctrl combinations on vim but ctrl+c or ctrl+a for example works as usual in insert mode. I hope this makes it a bit more clear.

Traveller answered 10/4 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.