Vim: Conflict with VSCode Ctrl + D key

  • Click thumbs-up 👍 on this issue if you want it!
  • Click confused 😕 on this issue if not having it makes VSCodeVim unusable.

The VSCodeVim team prioritizes issues based on reaction count.


BUG REPORT:

Environment:

  • VSCode Version: 1.18.0
  • VsCodeVim Version: 0.10.3
  • OS: Window version 1709

What happened: Unable to find substring with Ctrl+D, it moved cursor to end of selected string when pressed ctrl+D When VSCodeVim is enabled: 1

What did you expect to happen: When VSCodeVim is disabled: 2

This is my VSCodeVim setting

// Vim settings
    "vim.startInInsertMode": true,
    "vim.useCtrlKeys": false, 
    "vim.overrideCopy" :false,

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 93
  • Comments: 46 (6 by maintainers)

Most upvoted comments

For future dudes: handleKeys = true in @jpoon’s table above means

"vim.handleKeys": {
    "<C-d>": true
}

and not vim.handleKeys: true. Was a little bit confusing for me personally. 👍

useCtrlKeys = true useCtrlKeys = false
handleKeys = true VSCodeVim move page half down VSCodeVim move page half down
handleKeys = false remap to <D-d> remap to <D-d>
undefined VS Code default behavior VS Code default behavior

If it’s undefined. So if you don’t have a <C-d> config set under handleKeys, it should use Code’s behaviour for it.

Here’s a workaround I came up with. It’s not ideal but saved me from giving up on this plugin.

Add this to keybindings.json to quickly enable/disable VIM.

When you need to use cmd+d (like it was meant to be) you can disable the entire VIM plugin, do your multi-cursor editing, and then reenable VIM right afterwards.

{
     "key": "cmd+alt+v",
     "command": "toggleVim",
      "when": "editorFocus"
},

I did just find, reading the documentation, that if you’re in normal or visual mode and hit gb, then you can hit Cmd+d to keep adding to the selection, which works if it isn’t exactly intuitive. It would be nice thought if Cmd+d worked as expected in Insert mode.

However, there is an irritating thing: After a few selections are added, the screen’s scroll position stays the same, it just flashes as selections are added, so you can’t actually see each selection that’s added as you can without VSCode Vim enabled.

Since I still want to use Ctrl+d in normal mode for scrolling I’ve added a visual mode keybinding that just calls the standard VS Code command:

    "vim.visualModeKeyBindings": [
        {
            "before": [
                "<C-d>"
            ],
            "commands": [
                "editor.action.addSelectionToNextFindMatch",
            ]
        }
    ]

This seems to be working fine for me so far.

I usually use g b to get the result of ctrl+d. The same is mentioned in the documentation

Although it’s flagged as experimental, I’ve never had a problem with it

How do I undefine handleKeys to get the default VS Code behavior? I’ve tried a number of options, including…

"vim.handleKeys": {}

…and…

"vim.handleKeys": null

…but ⌘-D still flickers like mad as the selection grows, and the page fails to scroll as expected. I also tried unmapping ⌘-D in Keyboard Shortcuts, but that just made things worse! At this point, the only thing I can find as a workaround is adding a keyboard shortcut to “Vim: Toggle Vim Mode” so I can temporarily get VS Code’s default behavior quickly when I need it.

Hopefully I’m just missing something “obvious”…would love to not need the above workaround! 😃

I was trying a lot of solutions, and inspired by @majutsushi answer, I came up with this setup:

"vim.insertModeKeyBindings": [ {
        "before":   [ "<C-d>" ],
        "commands": [ "editor.action.addSelectionToNextFindMatch" ]
} ],
"vim.visualModeKeyBindings": [ {
        "before":   [ "<C-d>" ],
        "commands": [ "editor.action.addSelectionToNextFindMatch" ]
} ],
"vim.normallModeKeyBindings": [ {
        "before":   [ "<C-d>" ],
        "commands": [ "editor.action.addSelectionToNextFindMatch" ]
} ],
"vim.handleKeys": { "<C-d>": true }  // undefined also works

I encourage you to play with it. There are a lot of possibilities.

I usually use it as follows:

  1. In any mode highlight a word (e.g. in normal or insert mode just put a cursor inside a word),
  2. Press Ctrl+d to select other occurrences,
  3. Press Shift+a to switch to Insert mode with cursor at the end of all selected words,

Alternatively:

  1. Highlight a word,
  2. Press Ctrl+d to select other occurrences,
  3. Press v to go into Visual mode,
  4. Change cursor position with h or l,
  5. Press i to switch to Insert mode.

It is not necessary to add key binding to Normal mode, but I found it very useful.

[UPDATE: Fwiw, I was never able to properly get the hang of the workflow I’ve enumerated here. The best workaround for me so far is @commanderfun’s from Jan 16.]

Thanks for your : workaround, @indrakaw! I like that it’s both simple and configuration-free.

For anyone not wanting to experiment with vim.handleKeys and vim.useCtrlKeys, here’s how @indrakaw’s solution works for me. I’m spelling it out in great detail here, but don’t worry: it’s really quite simple. 😃

  1. Exit Insert Mode w/esc
  2. Make a visual selection, e.g., by placing the cursor on the word in question and hitting v i w
  3. Enter Ex Mode w/:
  4. Expand your selection to include the next match w/Command+D. (I’m on a Mac. Presumably this is Ctrl+D on Linux or Windows.
    • Add Shift (as in, Shift+Command+D) to skip a selection. This is handy to avoid multi-selecting names with conflicting capitalization, like, say, you’ve got a class called Foo and a variable called foo in a single file…
  5. Hit esc to return to command mode. At this point, the multi-selection can be edited with any of the usual techniques, including both Normal Mode and Insert Mode edits.

I think this issue should be reopen! I confirm none of the solutions presented here worked with my up-to-date VSCode / Ubuntu 19.10 env. There is a nice plugin that inserts mutiple-cursors functionality in Vim: https://github.com/terryma/vim-multiple-cursors. But I think it’s easier just to solve the insert-mode <C-d>: false problem rather than implement this plugin functionality . If I’m mapping <C-d> off, so it should work as expected, right? At least in the Insert Mode.

@imnickvaughn

In fact, both work for me(mine needs to add one line as below)…I’m not sure why your vs code can’t do it.

"vim.handleKeys": {
    "<C-a>": false,                 // select all
    "<C-c>": false,                //  copy
    "<C-n>": false,               //  new file
    "<C-d>": false,                // you want to use Ctrl-D in VS Code mode, then vim should not handle this.  You forgot this line in my configuration.
    "<C-x>": false,               // cut?
    "<C-w>": false              // close the tab
},
"vim.useCtrlKeys": true,           // Be default, it's true. So I didn't write it in my configuration. I mentioned  "vim.useCtrlKeys": false  because  you certainly use 'ctrl-f/b' and vim must use ctrl key. I think   "vim.useCtrlKeys": false   is wrong   for a vim user.

I found that “vim.useCtrlKeys”: false has some issues. Some works, such as Ctrl-a, Ctrl-n, but Ctrl-d still works in VIM mode. Again, just set “vim.useCtrlKeys”: true for Ctrl-F/B

"vim.handleKeys": { "<C-d>": false },

This worked for me. It selected multiple words with the same name. It puts you in -visual- mode. I then pressed v to get out of visual mode and into normal mode. Then I press a to start at the end of my selection and change from there.

No, {"<C-d>": false} does NOT work. There is obviously a bug in the plugin as it simply refuses to relinquish this key combo. It’s a good plugin otherwise, but this bug makes it unusable for me (and I’m not about to start using multi-keypress workarounds as suggested by some).

@eric-burel @amirmeimari you can disable the ctrl+d key in vim

  "vim.handleKeys": {
    "<C-d>": false,
  },

putting this in your vscode settings should work

Have been fighting this recently too; just discovered the problem goes away when I disable VSCodeVim, but I use it so much I don’t want to do that.

In VIM mode to select all matches use cmd+shift+L shortcut. To move selection to next find match and then add selection to the match stack without conflicts follow the next steps:

  • install the next plugin: https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command
  • go to user settings cmd+,
  • add to the bottom: “multiCommand.commands”: [ { “command”: “multiCommand.moveAndSelectMatch”, “sequence”: [ “editor.action.moveSelectionToNextFindMatch”, “editor.action.addSelectionToNextFindMatch” ] } ]
  • go to the keybindings.json file (cmd+k cmd+s then press to the file relevant name)
  • then add to the bottom of the file { “key”: “cmd+d”, “command”: “multiCommand.moveAndSelectMatch”, “when”: “editorFocus” },
  • make sure that any more keys not assigned when editorFocus.

I think this issue should be reopened! When I select “foo-bar” in the following code snippet and press Ctrl-D, the next “foo-bar” is not selected. Instead, the next “bar” or the next “foo” is selected, depending on which word the cursor currently stands.

bla
bla foo-bar bla
bla foobar bla
bla barfoo bla
bla foo bar bla
bla foo-bar bla
bla

This is my config:

"vim.useCtrlKeys": false,
"vim.handleKeys": {
    "<C-c>": false,
    "<C-d>": false,
    "<A-S-Up>": false,
    "<A-S-Down>": false
},

Tks for sharing. Just to know there are some brackets errors on snippet. 😉

I saw some guy coding in vim mode like a pro. I feel I can do that too. So I installed this plugin but was stuck on this problem. After struggling for some days, I have to uninstall this plugin, cause I use cmd+d really a lot. And, this happened THREE times in two years.

In VIM mode to select all matches use cmd+shift+L shortcut. To move selection to next find match and then add selection to the match stack without conflicts follow the next steps:

@andrewLucky1 Do you have more insight on this shortcut, is it a VS code shortcut, does it have a meaning in Vim? It seems to do exactly what ctrl+d does usually, selecting all instances.

g b does not seem to be equivalent to me, as it selects values one by one on each press. Or maybe I don’t understand the feature correctly?

In most case, I want to select all values, basically doing a research and replace but more intuitively with multiple cursors.

For future dudes: handleKeys = true in @jpoon’s table above means

"vim.handleKeys": {
    "<C-d>": true
}

and not vim.handleKeys: true. Was a little bit confusing for me personally. 👍

Bless you. Using "<C-b>": false for "vim.handleKeys" finally enabled me to hide/show the sidebar with Ctrl+B on Windows again (and likely Linux, macOS in particular doesn’t have this problem because of the separate Cmd key).

useCtrlKeys = true useCtrlKeys = false handleKeys = true VSCodeVim move page half down VSCodeVim move page half down handleKeys = false remap to <D-d> remap to <D-d> undefined VS Code default behavior VS Code default behavior If it’s undefined. So if you don’t have a <C-d> config set under handleKeys, it should use Code’s behaviour for it.

Excuse me, what does <D-d> mean?

It might because of unexpected key binds. Try to press : then try again, it works for me.

Try to use the trick instead before resolved:

  1. useCtrlKeys": false
  2. Move cursor to target text
  3. Set vim to normal mode with esc
  4. Select text with your mouse / touch pad
  5. Use cmd / ctrl + d of vscode
  6. Set vim to insert mode with i
  7. move your cursor, it may works with multiple cursors (not multiple selections)