How to use vim (key-bindings) with Visual Studio Code vim extension
Solution 1
Add the following to settings.json (open the Command Pallete and search for "User Settings"):
"vim.insertModeKeyBindings": [
{
"before": ["j", "j"],
"after": ["<esc>"]
}
]
That should do it.
Solution 2
If you running on Linux and have used setxkbmap
to remap Esc
to Caps-Lock
and have problems, I suggest the following workaround Fix for Esc remapping.
The solution is to add the following to your User Settings
"keyboard.dispatch": "keyCode"
You should save and restart after that
Solution 3
From this issue, I learned that you can use something like
{ "key": "j j", "command": "extension.vim_esc", "when": "editorTextFocus" },
But it does come with a problem of not being able to use j
for movement.
PS. I know this is not a complete answer but something to get going.
Related videos on Youtube
ganjan
Updated on February 20, 2020Comments
-
ganjan about 4 years
I just started using Visual Studio Code and think it's really great. Also installed the vim extension, but I'm struggling with mapping esc to a another key.
Normally I have this:
:imap jj <Esc>
And I can see that VS Code has a keybindings.json file. I tried this:
[{ "key": "jj", "command": "vim.Esc", "when": "editorTextFocus" }]
Also there is a settings.json file, so I tried:
{ "vim.keyboardLayout": "en-US (QWERTY)", "vim.insertModeKeyBindings": { "j": "vim.Esc" } }
Also did not work. So does anyone know how to use the a vim extension with VS Code where I can map
jj
toEsc
or something else toEsc
perhaps?-
sudo bangbang almost 8 yearsAre you using github.com/VSCodeVim/Vim ?
-
ganjan almost 8 yearsyes, I'm using github.com/VSCodeVim/Vim @sudobangbang
-
Gerry over 2 yearsyikes why would you ever want to do that...
-
Jarmos over 2 years@Gerry why not? I think it comes down to personal preferences, isn't it? I use Neovim like 7 out of 10 times a day. But there are a few moments when I would like use VSCode instead. And during those few moments, I would like to stay within my favoured Neovim-like navigation environment. I don't see why it could be an issue.
-
-
ganjan almost 8 yearsThis almost works, but when I type j the application freeze waiting for second key.. Have to make sure it only happen when I'm in vim insert mode...
-
jarandaf about 6 yearsWith current version of VSCodeVim, it works with
<Esc>
instead of<esc>
. -
sjt003 about 6 yearscan you add another key after "<Esc>" ? like this
"after": ["<Esc>", "l"]
? -
gwintrob almost 4 yearsThis has worked for a long time for me, but I'm starting to see weird behavior (see here). The first j seems to stay in insert mode and then the second j moves back a character and sometimes deletes the line. Any idea what might cause this?
-
Isaac Pak almost 4 years@gwintrob All of the sudden I get this mess too. Did the vim extension auto update or is this a vscode problem? I remapped to other double letters (ie. "x", "x") and still get the same behavior.
-
Isaac Pak almost 4 yearsNevermind. I got the fix from your github issue. link kudos!
-
Shadoath over 3 years@st003 Yes, I have mine set to run
"after": ["<Esc>", ":", "w", "<Enter>"]