Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with VSCode Ctrl + D key #2144

Closed
ghost opened this issue Nov 14, 2017 · 46 comments
Closed

Conflict with VSCode Ctrl + D key #2144

ghost opened this issue Nov 14, 2017 · 46 comments

Comments

@ghost
Copy link

ghost commented Nov 14, 2017

  • 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,
@jdhines
Copy link
Contributor

jdhines commented Nov 14, 2017

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.

@jdhines
Copy link
Contributor

jdhines commented Nov 14, 2017

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.

@ghost
Copy link
Author

ghost commented Nov 15, 2017

Thanks, it worked in normal mode.
As you pointed out, after a few selection are added, it stops scrolling and just flashes the screen, somehow irritating, looks like I need to scroll the screen myself. Hope it will be improved

@Chillee
Copy link
Member

Chillee commented Nov 29, 2017

The reason for this is that we don't support any semblance of "selections" in insert mode. The scroll position thing is something that should be fixable. I'll try to take a look sometime.

@jpoon
Copy link
Member

jpoon commented Jan 16, 2018

I think #2269 resolves this issue? If not, feel free to re-open.

@ghost
Copy link
Author

ghost commented Jan 16, 2018

If I understand correctly, ctrl+D will be Code default behavior now if vim.useCtrlKeys: false?

    "vim.startInInsertMode": true,
    "vim.overrideCopy" :false,
    "vim.useCtrlKeys": false,

Looks like it's not fixed
peek 2018-01-16 18-23

OS: Arch Linux (x86_64 Linux 4.14.13-1-ARCH)
Code: 1.19.2
Vim: 0.10.10

@jpoon
Copy link
Member

jpoon commented Jan 17, 2018

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.

@rksys
Copy link

rksys commented Jan 17, 2018

@jpoon you just saved me from struggling ;-)

@MrYakobo
Copy link

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. 👍

@jpoon
Copy link
Member

jpoon commented Jan 17, 2018

Ok, seems like this is resolved.

@jpoon jpoon closed this as completed Jan 17, 2018
@clozach
Copy link

clozach commented Mar 21, 2018

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! :)

@t-animal
Copy link

t-animal commented Jul 9, 2018

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
},

@andrewLucky1
Copy link

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.

@glrodasz
Copy link

@andrewLucky1 I tried it but it didn't work for me. What I have done is disable the multicursor keyboard shortcut for vim, the problem is that select the whole word doesn't work for all the selected instances using Shit + Alt + or Shit + Alt + .

{
    "key": "cmd+d",
    "command": "-extension.vim_cmd+d",
    "when": "editorTextFocus && vim.active && vim.use<D-d> && !inDebugRepl"
}

Anyone have figured out how to solve it?

@lanza
Copy link

lanza commented Dec 9, 2018

This seems to have broken rebinding of <C-d> in insert mode. It now ignores any insert-mode remapping.

@lzfee0227
Copy link

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)

@Askannz
Copy link

Askannz commented May 21, 2019

I confirm this is still a bug : the "vim.handleKeys": {"<C-d>": false} setting is only applied to Normal mode, the Vim extension still hijacks Ctrl + D in Insert mode.

EDIT : actually it also does something in Normal mode, the behavior of Ctrl + D is different when the extension is enabled.

@ferrarop
Copy link

ferrarop commented Jun 4, 2019

I have the same problem.
I've tried with

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

and

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

and

"vim.useCtrlKeys": false,
"vim.handleKeys": {
}

I'm on macOS. Nothing seems to work. The only working solution, for me, is disabling vim mode.
It "kinda works" in normal mode, but the scrolling is not working as intended.

@indrakaw
Copy link

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

@kigawas
Copy link

kigawas commented Jul 2, 2019

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?

@paulina-grunwald
Copy link

paulina-grunwald commented Jul 27, 2019

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.

  • remark: vim extension also have been installed!
    https://marketplace.visualstudio.com/items?itemName=vscodevim.vim
    Get done! Good luck!

Thanks a lot. this helped me to solve the problem on mac 🙏 is it possible to select one by one not all of the at once?

@sndnyang
Copy link

sndnyang commented Sep 5, 2019

@frarees @paulina-grunwald
I'm using Windows10. But I think it should be fine:
My configuration is:

"vim.handleKeys": {
        "<C-a>": false,
        "<C-c>": false,
        "<C-n>": false,
        "<C-x>": false,
        "<C-w>": false
    },

"vim.useCtrlKeys": false disables vim to use CTRL. Certainly you can't use CTRL-F/B for page down/up.

In my configuration, I just specified some shortcuts which should be handled by VSCode.
vim.handleKeys, "a keybinding': false means this keybinding is handled by VSCode instead of vim ((( if you enable vim mode, all keybindings will be handled by vim. We just select some common bindings to work in VSCode mode, like CTRL+a select all). I think some previous discussions are confusing.

By the way, I find "<C-,>": false, doesn't work which should open the settings of VSCode. However, it doesn't do anything(VIM doesn't map it to any functionality).

@imnickvaughn
Copy link

imnickvaughn commented Sep 8, 2019

Darn, none of these things are working for me.

@andrewLucky1 Tried this solution, but after selecting something and pressing ctrl+d it will deselect that thing and select a few of the other similar things.. but even that is not reliable sometimes it just deselects everything, sometimes it just picks something with that string within it and then starts selecting between all of those things and nothing...

and the other solutions using
vim.handleKeys
and
vim.useCtrlKeys
unfortunately, do not work either for me... they are fairly straight forward, just put those things in your settings, yet they don't work for my completely up to date vs code...

I've tried adding these and all the in betweens...

    "vim.handleKeys": {
        "<C-a>": false,
        "<C-c>": false,
        "<C-n>": false,
        "<C-x>": false,
        "<C-w>": false
    },
    "vim.useCtrlKeys": false,

and

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

I was really excited to use vim and level up my coding but vs code's multi-select is something I can't imagine losing!

@jpoon please this SHOULD DEFINITELY BE REOPENED thanks!
As you can see many are still having the same issues

@sndnyang
Copy link

sndnyang commented Sep 8, 2019

@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

@clozach
Copy link

clozach commented Nov 16, 2019

[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.

@arsaccol
Copy link

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).

@alac1984
Copy link

alac1984 commented Nov 28, 2019

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.

@bluedusk
Copy link

This is still now working with latest vscode and vim plugin. I think the issue should be reopen.

@commanderfun
Copy link

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"
},

@sahilrajput03
Copy link

Thanks guys!!

@beantowel
Copy link

Does anyone know why "ctrl+pageDown/pageUp" doesn't work when vim is in insert mode? How do you switch between opened tabs?

@vitebo
Copy link

vitebo commented Sep 14, 2020

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

@eric-burel
Copy link

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.

@amirmeimari
Copy link

Why this issue is closed? It's not fixed yet. common I like this plugin and I don't want to give up on it!

@vitebo
Copy link

vitebo commented Feb 26, 2021

@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

@gorsat
Copy link

gorsat commented Mar 15, 2021

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).

@Fingel
Copy link

Fingel commented Mar 29, 2021

I had always thought cmd+d multi select behavior in VScode was just weird and not as good as Sublime's. Then I tried disabling this plugin and it works perfectly. This should definitely be re-opened. I can confirm that the handleKeys config option does not seem to work.

@Dozorengel
Copy link

@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

however, it's a workaround, it works like a charm

@majutsushi
Copy link

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.

@dijonkitchen
Copy link

I think there was a lot of confusion here between differences of the Ctrl modifier key between Windows users and macOS users.

For what it's worth, after pressing "Ctrl+d" on macOS with the Vim extension, I had to select an environment and then I was able to page down as if it was using Vim bindings.

@jonsmithers
Copy link

Where is that environment setting?

@aztack
Copy link

aztack commented Jun 26, 2022

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.

@DriesVerb
Copy link

DriesVerb commented Jul 4, 2022

"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.

@mwojtulewicz
Copy link

mwojtulewicz commented Nov 18, 2022

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.

@fcsbr
Copy link

fcsbr commented Dec 23, 2022

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

@pwneddesal
Copy link

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. 👍

does not work it still do the copy pasting of code, an not vim's page down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests