10

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

marcelocra
  • 2,094
  • 2
  • 24
  • 37
Yoquec
  • 261
  • 2
  • 9

3 Answers3

16

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.

Yoquec
  • 261
  • 2
  • 9
2

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.

SamTheProgrammer
  • 1,051
  • 1
  • 10
  • 28
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'
mattb
  • 2,787
  • 2
  • 6
  • 20
  • 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!! – Yoquec Nov 05 '21 at 08:34