I use Debian and I switched from Vim to Visual Studio Code, when I noticed, that there is a Vim movement extension for VS Code from vscodevim. While I was using Vim, I mapped my Caps lock key to the ESC key. In Vim it works perfectly, but VS Code is not reacting on a Caps lock input.
I hope there is a solution. If there are any questions feel free to ask.
This is how I changed my keyboard layout:
I navigated to /etc/default/
and edited the keyboard file. This is how it looks now
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="de"
XKBVARIANT=""
XKBOPTIONS="caps:escape"
BACKSPACE="guess"
The Caps lock key works also in other programs e.x. "Synaptic Package Manager"
Late answer, but may be useful for someone:
Switched CAPS and ESC in Ubuntu over the keyboard preferences section. Worked in almost all applications, but not in Visual Studio Code.
So I modified VS Code settings:
{
"keyboard.dispatch": "keyCode"
}
and it worked.
For those who have the same problems on Linux:
If in your system wide config, Caps Lock is Esc, Esc is Caps Lock ( ['caps:swapescape'] ),
disable the key mapping in your system. Make it default.
In VSCode, press ctrl+shift+p and select Preferences: Open Keyboard Sortcuts
search for the vim_escape
double click on it and press original Caps Lock and save it.
Edit your keymap config in your system.
That is it.
There is no problem. Keys are working as expected.
Enlighten by an answer from this question.
In Visual Studio Code, how to toggle between vim-emulation and no-vim-emulation when the vscodevim extension is installed?
Another solution is
Click the "Gear icon" -> Keyboard Shortcuts->type "esc" or "Escape" ->
find extension.vim_escape -> edit by click the pencil icon or right click choose change keybinding
->type you desired key and ENTER
Set the Caps-lock to act as Esc in your settings
Post this in your keybindings json for vscode (Ctrl-K Ctrl-S -> open the JSON from the icon on the top right corner):
{
"key": "capslock",
"command": "extension.vim_escape",
"when": "editorTextFocus && vim.active && !inDebugRepl"
},
If you are looking for a system wide tool, you might be interested in keyd https://github.com/rvaiya/keyd. You can avoid this setup. The readme has an example on how setup caps lock as both ctrl and esc.
Ubuntu solution
First make sure you swaped escape with capslock like: source
gsettings set org.gnome.desktop.input-sources xkb-options "['caps:swapescape']"
Then inside VSCode press ctrl+shift+p search for Preferences: Open keyboard Shortcuts (JSON) (it will open keybindings.json) and paste:
{
"key": "capslock",
"command": "extension.vim_escape",
"when": "editorTextFocus && vim.active && !inDebugRepl"
},
{
"key": "escape",
"command": "-extension.vim_escape",
"when": "editorTextFocus && vim.active && !inDebugRepl"
}
Reload VSCode and you are good to go.
Windows solution
Install AutoHotkey
Go to AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\
Create a file caps_to_esc.ahk and insert code:
#IfWinActive ahk_exe Code.exe
Capslock::Esc
Esc::Capslock
#IfWinActive
Save, run the file and you are good to go.
Related
How can I disable this backspace behavior and remove letters in strandard way?
For some reasons in Sublime Default (Windows).sublime-keymap were changed backspace hotkey actions. I didn't add new plugins or macroses. Probably some kind of bug.
I did next steps to fix it:
Input sublime.log_commands(True)
Press backspace and check what happens. I seen this wrong command that added in file for unknown reason: command: run_macro_file {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}
Open Preferences -> Key Bindings input standard backspace action by command: { "keys": ["backspace"], "command": "left_delete" },
How does one change the shortcut to switch between insert mode and normal mode?
Where can I find a list of all vim extension shortcuts and their commands?
I searched for them in keyboard shortcuts but you can only search by keybindings which complicates things.
Thanks!
I settled on mapping ^ + [ to the command extension.vim_escape. Additional detail for the community:
Open keybindings.json
⇧ + ⌘ + p or ctrl + shift + p by default
Enter Preferences: Open Keyboard Shortcuts
Select the file icon in the top-right corner of the pane:
Add the following JSON object to the list:
{
"key": "ctrl+[",
"command": "extension.vim_escape",
"when": "editorTextFocus && vim.active && !inDebugRepl"
}
Notes:
Setting "vim.useCtrlKeys": true in settings.json might also be required
I assume that a different escape sequence could also be used
I'm using vscodevim.vim version v1.17.2 on macOS
In the keyboard shortcuts UI (not the JSON file), searching for extension.vim_ showed a list of Vim "Commands" that can be sent to the Vim emulator according to their keybindings
For example, after performing the above, searching for extension.vim_escape provides the following:
Using the VIM extension for VS Code is there a key command to jump to the explorer pane and then back to the work window?
I cannot find anything in the docs.
I'm hoping there is something like my Control+N binding for NERDTree which lets me open the file viewer, pick a file and then close it.
I am not familiar with NERDTree, but I think Ctrl+Shift+e does what you are asking in vs code. Alternatively Ctrl+p may be an alternative? You could look at
linux keyboard shortcut for more reference.
The link is also available in Help > Keyboard Shortcut Reference
EDIT: I'm adding the equivalent shortcut for Mac OS since it's different layout. However, I don't use Mac OS.. So I add this without being able to confirm :
Shift+Command+E
Mac OS Keyboard shortcut for VS Code
Windows keyboard shortcuts are very similar to linux ones. So, I'll just include the link to windows shortcuts doc here. Windows Keyboard shortcut for VS Code
Just my two cents:
If you are using the Vim extension for VS code you can add this to your settings.json file:
"vim.normalModeKeyBindings": [
{
"before" : ["<leader>","a"],
"commands" : [
"workbench.view.explorer"
]
}
]
The exemple above uses <leader> + a while in normal mode to display the file explorer where you can navigate the file list with j and k. Pressing ENTER will open the file under the cursor and close the file list.
To set up a leader key just add in your settings.json:
"vim.leader" : "," ,
In addition to Santiago's comment, you're able to open a file in a new tab from the explorer (Cmd + Shift + E) with Ctrl + Enter for MacOS. I'm not sure about Windows or Linux.
If you want to go to a file with VIM in VSCode:
Enter Normal Mode (Esc)
Place cursor over file you want to jump to, e.g. between the quotes - "../models/postMessage.js";
Press lowercase gd - Go to definition
I use VSCode with the VSCodeVim extension. When in Insert Mode, I can press "CMD-S" to save. When I do, I would also like to exit Insert Mode automatically instead of pressing "ESC" as well.
Is this possible?
I was looking for a solution similar to this issue as well.
It appears that multiple commands cannot be mapped to key bindings in vscode; however, I've found an extension, macros, that let's you do this.
If you use the below steps with the macros extension, I believe that you'll have the solution you're looking for, until vscode implements something to address this feature request.
Step one, edit user settings with the below:
"macros": {
"saveAndExitVimInsertMode": [
"workbench.action.files.save",
"extension.vim_escape"
]
}
Step two, edit keyboard bindings:
{
"key": "cmd+s",
"command": "macros.saveAndExitVimInsertMode"
}
VSCodeVim extension supports insert mode key bindings. Here is a link to the extension readme that describes this feature.
Here is a snippet you could put in your settings.json.
"vim.insertModeKeyBindingsNonRecursive": [
{
"before": [ "<C-s>" ],
"commands": [
{ "command": "workbench.action.files.save" },
{ "command": "extension.vim_escape" }
]
}
],
After reloading your vscode window you can pressing ctrl+s to exit insert mode and save the file.
open Show Command Palette (Ctrl+Shift+P). enter 'open keyboard shortcut' ,
search 'extension.vim_escape' and edit it to be 2 times caps lock key.
In Sublime Text, when I press Ctrl+B, it runs my application. Is there a hotkey to force it to stop running?
I'm debugging some code that often hangs, and Sublime Text ends up completely hanging. I'd like to know what hotkey I can press to stop this.
CtrlBreak (Windows/Linux) will cancel a build that is in progress. There is no default key binding for OS X, but you can create your own if you wish. Navigate to Sublime Text -> Preferences -> Key Bindings - User and add the following:
{ "keys": ["super+alt+b"], "command": "exec", "args": {"kill": true} }
If you don't have any custom key bindings yet, make sure to wrap the above with square brackets [].