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:
What did you expect to happen:
When VSCodeVim is disabled:
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)
For future dudes:
handleKeys = true
in @jpoonâs table above meansand not
vim.handleKeys: true
. Was a little bit confusing for me personally. đ<D-d>
<D-d>
If itâs undefined. So if you donât have a
<C-d>
config set underhandleKeys
, 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.I did just find, reading the documentation, that if youâre in normal or visual mode and hit
gb
, then you can hitCmd+d
to keep adding to the selection, which works if it isnât exactly intuitive. It would be nice thought ifCmd+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:
This seems to be working fine for me so far.
I usually use
g b
to get the result ofctrl+d
. The same is mentioned in the documentationAlthough 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âŚ
âŚandâŚ
âŚ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:
I encourage you to play with it. There are a lot of possibilities.
I usually use it as follows:
Ctrl+d
to select other occurrences,Shift+a
to switch to Insert mode with cursor at the end of all selected words,Alternatively:
Ctrl+d
to select other occurrences,v
to go into Visual mode,h
orl
,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
andvim.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. đesc
v i w
:
Command+D
. (Iâm on a Mac. Presumably this isCtrl+D
on Linux or Windows.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 calledFoo
and a variable calledfoo
in a single fileâŚ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.
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 pressa
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
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:
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.
This is my config:
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.@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.
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).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:
useCtrlKeys": false