user1283776
user1283776

Reputation: 21764

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

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?

Upvotes: 23

Views: 20439

Answers (6)

alex.p
alex.p

Reputation: 2739

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.

Upvotes: 2

5had0w
5had0w

Reputation: 1

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.

Upvotes: 0

npfoss
npfoss

Reputation: 490

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

Upvotes: 3

Yanfeng Huo
Yanfeng Huo

Reputation: 91

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

Upvotes: 9

MatrixManAtYrService
MatrixManAtYrService

Reputation: 9131

I set up a "toggleVim" keybinding, like so: https://stackoverflow.com/a/61652769/1054322

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

Upvotes: 6

isAif
isAif

Reputation: 2334

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.

Upvotes: 20

Related Questions