Is there a way to remap Caps_Lock to be the escape key on vscode's vim?
Asked Answered
E

3

12

Problem

I want to use Caps_Lock as the key to exit insert mode in Visual Studio code's vim extension. I have already remapped the keys in Xorg with Xmodmap, but Visual studio doesn't seem to really matter.

My VScode settings

As you can see, I already tried with "vim.insertModeKeyBindings", but it only disables the Escape key, leaving me thinking that Caps_lock has another key name/keysym, but I can't seem to find it.

{
    "editor.fontFamily": "'Inconsolata-g for Powerline'",
    "editor.fontSize": 16,
    "liveshare.authenticationProvider": "GitHub",
    "vim.enableNeovim": true,
    "code-runner.enableAppInsights": false,
    "code-runner.runInTerminal": true,
    "workbench.startupEditor": "newUntitledFile",
    "workbench.editorAssociations": [
        {
            "viewType": "jupyter.notebook.ipynb",
            "filenamePattern": "*.ipynb"
        }
    ],
    "workbench.colorTheme": "BeardedTheme Anthracite",
    "extensions.autoUpdate": "onlyEnabledExtensions",
    "vim.vimrc.enable": true,
    "vim.vimrc.path": "$HOME/.config/nvim/init.vim",
    "editor.fontWeight":"bold", 
    "vim.insertModeKeyBindings": [
        {
            "before": ["<Esc>"],
            "after": ["<Caps_Lock>"]
        }
   ]
}

Another thing i'd like to address is that i already have j,k and their combinations to exit insert mode. Is that a default?


Huge thanks in advance to anybody offering to help!!

Election answered 30/5, 2021 at 19:44 Comment(6)
This question has nothing to do with Vim so there is no need for a "vim" tag.Coprology
How is this not related with Vim?Election
You are not using Vim.Coprology
True, I'm using NeoVim, thanks for noting!Election
Maybe just Capslock, see https://mcmap.net/q/1007766/-vs-code-on-win-10-create-keybinding-for-capslock-i-j-k-l-to-act-as-arrow-buttons for some variations on capslock that I tried for a different question.Mortgagor
I guess the tag neovim isn't applicable either. It's about VSCode and its Vim extension. So neither vim nor neovim.Donell
E
19

Solution

As this problem arose in Linux and, I already changed my settings in Xmodmap, it seems that VScode not respecting remappings with xkbmap is a known issue and should be fixed by adding "keyboard.dispatch": "keyCode" in VScode's settings.json and reopening VS.

Election answered 31/5, 2021 at 8:20 Comment(0)
M
4

Press CTRL + SHIFT + P to open the command pallete.

Then, click on the settings button on any of the commands.

This opens the keybindings.

Search extension.vim_escape

Change this to CAPS_LOCK.

The only issue with this is that it still capitalises things when you re-enter insert mode, so you have to press it twice.

Markusmarl answered 22/11, 2021 at 17:56 Comment(0)
U
0

I see you already found a possible workaround, but I wonder if the 'xcape' tool (apt install xcape) can help with the following in your bashrc?

# set capslock to escape key  
setxkbmap -option ctrl:nocaps
xcape -e '#66=Escape'
Underclothes answered 31/5, 2021 at 9:36 Comment(1)
It seems it also worked, but as the problem was isolated to VScode and I hadn't really encountered any problems in other applications, I didn't want to change my system config. I already used Xmodmap and looked good for me. However, it does seem to be a good alternative. Thanks for your answer!!Election

© 2022 - 2024 — McMap. All rights reserved.