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

Mapping capslock to esc has issues #854

Closed
billti opened this issue Oct 6, 2016 · 33 comments
Closed

Mapping capslock to esc has issues #854

billti opened this issue Oct 6, 2016 · 33 comments

Comments

@billti
Copy link

billti commented Oct 6, 2016


Please thumbs-up 👍 this issue if it personally affects you! You can do this by clicking on the emoji-face on the top right of this post. Issues with more thumbs-up will be prioritized.


What did you do?

Attempted to map the caps lock key to the escape key, via the below in keybindings.json

{"key": "capslock", "command": "extension.vim_escape"} 

Note: I also tried via the below, using "capslock" and "", but this had no effect, as it appears from the codebase <CapsLock> isn't recognized notation.

{
    "vim.insertModeKeyBindings": [
        {
            "before": ["capslock"],
            "after": ["<Esc>"]
        }
    ]
}

What did you expect to happen?

This should allow me to exit insert mode via the close-by caplock key.

What happened instead?

It does kinda work via the first form above, however if also toggles caps lock on/off, which makes it impossible to use (as every key press is then a capital after exiting insert mode). Preferably the "vim.insertModeKeyBindings" would work, and recognize the capslock key and intercept it - preventing it from toggling caps-lock.

Technical details:

  • VSCode Version: 1.5.3
  • VsCodeVim Version: 0.3.0
  • OS: Windows 10
@jpoon
Copy link
Member

jpoon commented Oct 7, 2016

Interestingly, I don't see the capslock key being bubbled up into our extension. We'll need to ask VS Code to add this to their extension API.

@billti
Copy link
Author

billti commented Oct 8, 2016

Actually, I just noticed even in Windows this usually requires some system changes via the registry or a utility to work correctly - so maybe it wasn't as simple as I hoped :-/ See http://vim.wikia.com/wiki/VimTip75

@johnfn
Copy link
Member

johnfn commented Oct 10, 2016

Yeah, Vim does not support caps lock mapping. People generally map it with some sort of broader keymapping program.

@johnfn johnfn closed this as completed Oct 10, 2016
@vyorkin
Copy link

vyorkin commented Oct 10, 2016

for Mac OS X I personally use Seil + Karabiner or Karabiner-Elements (if you are on Sierra).
you could take a look at this awesome post: http://stevelosh.com/blog/2012/10/a-modern-space-cadet/

@ljbuza
Copy link

ljbuza commented Nov 26, 2016

On Linux Gnome desktops, Tweak Tool, under the "Typing" menu, will let you set your cap lock behavior. Setting it to "Make Caps Lock an additional ESC" works well for me.

@clamydo
Copy link

clamydo commented Apr 6, 2017

Doing

setxkbmap -option caps:swapescape

on Linux swaps the escape and caps lock Xorg wide. But since code 1.11 this extension does not recognise this. To get out of insert mode, I have to press the original esc key, which at the same time toggles CAPS. This is really annoying.

Might be a problem with code itself: microsoft/vscode/issues/23991

@johnfn
Copy link
Member

johnfn commented Apr 6, 2017

Would probably be good to test with other parts of VSCode that use an ESC key to trigger something. We don't really have anything to do with capslock binding, unfortunately!

@tallpants
Copy link

It's definitely an issue with VS Code itself. Going back to 1.10 brings back the expected behavior, so it's something in the 1.11 update that's broken it.

@johnfn
Copy link
Member

johnfn commented Apr 6, 2017

@areyoureddy In that case, definitely go open up an issue on their repository then. :)

@tallpants
Copy link

microsoft/vscode#23991 Already done 👍

@Fr4nks
Copy link

Fr4nks commented May 24, 2017

Issue resolved?
keybindings.json
// Place your key bindings in this file to overwrite the defaults
[ {"key": "capslock", "command": "extension.vim_escape",
"when": "editorTextFocus && vim.active && !inDebugRepl" }
]

Ubuntu 16.04, VS Code 12.2.2
Doesn't work correctly in window 10.

@freddie-freeloader
Copy link

@Fr4nks This works for me just well under Linux.

@GummyDonut
Copy link

@Fr4nks solution worked for me to, thank.

@nayzawoo
Copy link

@Fr4nks Thanks!

@nazarimilad
Copy link

nazarimilad commented Jul 20, 2017

@Fr4nks First it didn't work for me. But after adding "keyboard.dispatch": "keyCode" in the settings file which was suggested as a workaround here, it's now working correctly.

VS Code version: 1.14.1

@hui00
Copy link

hui00 commented Sep 10, 2017

@Fr4nks thank you!

@ghost
Copy link

ghost commented Feb 7, 2018

@Fr4nks Thanks!

@Ding-Fan
Copy link
Contributor

Ding-Fan commented Apr 7, 2018

I put this in keybinds.json

// Place your key bindings in this file to overwrite the defaults
[
  {
    "key": "capslock", 
    "command": "extension.vim_escape",
    "when": "editorTextFocus && vim.active && !inDebugRepl" 
  }
]

And toggle this in User Settings

"keyboard.dispatch": "keyCode"

Now I can use caps lock as esc in vim insert mode. But
I have to press caps lock again because it capitalize my letters. 😓

@Chillee
Copy link
Member

Chillee commented Apr 9, 2018

@Ding-Fan I suggest using some kind of external caps lock to escape rebinding program. I use caps2esc on Arch Linux.

@Ding-Fan
Copy link
Contributor

Ding-Fan commented Apr 9, 2018

@Chillee I'm using Karabiner-Elements on macOS now, it's amazing. 😃

@mmyoungman
Copy link

In case it is of use to anyone, on macOS, I had set capslock to be escape, and it was previously working fine, but after using setting sync to import my settings, I stopped being able to get out of insert mode. It turned out that "vim.enableNeovim": true, was the culprit. I set it to false and everything was fine again.

@janhesters
Copy link

janhesters commented Dec 21, 2018

On mac you can also map caps lock natively: https://stackoverflow.com/questions/127591/using-caps-lock-as-esc-in-mac-os-x/40254864#40254864

@rimseg
Copy link

rimseg commented Mar 21, 2019

On Fedora 29 I just needed to change an option in the Settings (File > Preference > Settings).

Keyboard: Dispatch "keyCode"

@bergmul
Copy link

bergmul commented Mar 27, 2019

@Ding-Fan I suggest using some kind of external caps lock to escape rebinding program. I use caps2esc on Arch Linux.

I'm also using caps2esc and it works fine everywhere but in code. Sometimes it works for a couple of minutes, then pressing capslock does not trigger esc anymore.

EDIT: Adding "keyboard.dispatch": "keyCode" to user configs solves the problem. Thank you, @Fr4nks.

@n0irx
Copy link

n0irx commented Aug 8, 2019

Issue resolved?
keybindings.json
// Place your key bindings in this file to overwrite the defaults
[ {"key": "capslock", "command": "extension.vim_escape",
"when": "editorTextFocus && vim.active && !inDebugRepl" }
]

Ubuntu 16.04, VS Code 12.2.2
Doesn't work correctly in window 10.

works on ubuntu

@seanwarman
Copy link

If anyone's wondering, as I had a problem finding keybindings.json through the vscode UI, it's in ~/.config/Code/User/.

And you can find some docs about it in VSCode's Docs

@mjarkk
Copy link

mjarkk commented Oct 6, 2019

@seanwarman In vscode you can get to the keyboard shortcuts using:
Ctrl + Shift + P and type Open Keyboard Shortcuts (json)

@Christopher-Hayes
Copy link

Christopher-Hayes commented Feb 11, 2020

For Windows users, after realizing how difficult it would be to implement with VS code settings, I found just changing the registry to be much easier and less finnicky. This same guide shows how to do it with various tools like AHK too. https://vim.fandom.com/wiki/Map_caps_lock_to_escape_in_Windows
For Windows 10, I created a file.reg with the following text:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,3a,00,46,00,01,00,3a,00,00,00,00,00

Double-clicked that file from explorer, then restarted my computer and it works like a charm. Of course, if you use the CAPS lock outside VS code, this solution isn't for you.

@bradleysawler
Copy link

Win10 I had a similar issue as others by having to 2nd press the cap lock to turn the cap lock back off. So I decided to just map CapLock + CapLock. So a double caps Esc and turns the caps back off.

@Mhmdrza
Copy link

Mhmdrza commented Nov 16, 2021

ctrl + {

Activates the normal;

also ctrl + c
also command + c

@SSmJaE
Copy link

SSmJaE commented Jan 23, 2022

I found a perfect way to map caps lock to ESC on Windows 10 ("keyboard.dispatch": "keyCode" doesn't take effect), and only works in VS Code, has no effect on other programs like games

Using AutoHotkey
here is the code

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2

#IfWinActive, Visual Studio Code
CapsLock::Escape
ScrollLock::CapsLock      

@whale124
Copy link

whale124 commented Feb 4, 2022

@Ding-Fan I suggest using some kind of external caps lock to escape rebinding program. I use caps2esc on Arch Linux.

I'm also using caps2esc and it works fine everywhere but in code. Sometimes it works for a couple of minutes, then pressing capslock does not trigger esc anymore.

EDIT: Adding "keyboard.dispatch": "keyCode" to user configs solves the problem. Thank you, @Fr4nks.

It works in my Ubuntu!
Thank you

@bnpysse
Copy link

bnpysse commented Jan 29, 2023

I put this in keybinds.json

// Place your key bindings in this file to overwrite the defaults
[
  {
    "key": "capslock", 
    "command": "extension.vim_escape",
    "when": "editorTextFocus && vim.active && !inDebugRepl" 
  }
]

And toggle this in User Settings

"keyboard.dispatch": "keyCode"

Now I can use caps lock as esc in vim insert mode. But I have to press caps lock again because it capitalize my letters. sweat

How to do changing twice to one?

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