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.
Related
I'd like to customize some of the Sublime Text 3 keybindings to mimic IntelliJ IDEA. One of them is opening a file from the current project, also known as Goto Anything in Sublime jargaon. I followed the instructions in this answer to find out that the default key binding for "Goto Anything" is ⌘ + p on a Mac, like so:
{ "keys": ["super+p"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} }
I added a new keybinding as follows:
[
{ "keys": ["shift+shift"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} }
]
It, however, doesn't work; pressing shift twice in rapid succession does precisely nothing. When I open the console, I see the following message:
Unable to open /Users/me/Library/Application Support/Sublime Text
3/Packages/Default/Default (OSX).sublime-keymap
According to this ticket, this message is harmless but misleading, and is just an indication that Sublime is opening a file.
What's wrong then?
OP here; I found this post in Sublime blog.
ST doesn't support using only modifier keys in a keybinding.
I am working with the sublime 3 text editor. I am modifying the User version of the keymap, however, it does not seem to be replacing the default keymap hotkeys. Specifically, in the Default keymap, I see the following assigned for the "copy" hotkey:
{ "keys": ["ctrl+insert"], "command": "copy" },
{ "keys": ["ctrl+c"], "command": "copy" },
There are two hotkeys assigned for the copy command, and I am not sure why. I use the latter command in my User keymap, but the hotkey is not working. The ctrl+insert hotkey is the one that is taking precedence.
Is there a way to modify the Default keymap for Sublime?
I don't see this conflict. But if you do, you can set a hotkey command to none if you don't want it to use.
{
"keys": ["ctrl+insert"],
"command": "none"
},
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.
I've gone over the documentation and the looked at the question:
How to use vim (key-bindings) with Visual Studio Code vim extension and I still can't define new keys in the Vim extension for Visual Studio Code.
I'm trying two things in my settings.json. Trying to delete a full tab - instead of just a single space (like vim does) - with backspace.
"vim.insertModeKeyBindings": [
{
"before": "backspace",
"after": "shift+backspace"
}
]
And also to change between editor panes with space, w, w (like using a leader key):
"vim.keybindings": [
{
"key": ["space", "w", "w"],
"command": "workbench.action.navigateEditorGroups",
"when": "editorFocus"
}
]
But I can't get any of those to work.
In my Sublime Text 3, the shortcut Ctrl+A moves cursor to the front of line as expected. However, Ctrl + E does not move cursor to the end of line. Then, I find out that this works: Command+RightArrowKey on Mac.
Anyone knows why Ctrl+E does not work as expected in the official shortcut documentation? What command shall I configure in the keybinding map?
My User key binding is very simple.
[
{ "keys": ["shift+space"], "command": "move", "args": {"by": "characters", "forward": true} },
]
When keys don't do what you expect in ST3 it's a good idea to install FindKeyConflicts
Install it through Package Manager and it'll help you work out why things aren't doing what you thought they should
The shortcuts listed are specific to the platform and the version of the Sublime Text. Here is the list of all the shortcuts, there is also a comparison chart here. Further, if you are getting started with Sublime Text3 this link might prove helpful.