Sublime Text 2 already supports normal Vim bindings. However, I'd like to have it support saving the current file when pressing space in command mode.
This key binding has become one of my number one features I love about vim.
However, when trying to write this key binding, Sublime Text 2 seems to ignore it:
{ "keys": ["space"], "command": "save",
"context":
[
{ "key": "setting.command_mode", "operand": true }
]
}
Sublime Text 2 seems to not recognize "space".
It much rather has to be like this:
{ "keys": [" "], "command": "save",
"context":
[
{ "key": "setting.command_mode" }
]
}
Related
I want to copy the Move Line Up/Down keyboard shortcut of VS Code to Sublime Text 3 which uses Ctrl+Up/Ctrl+Down key bindings, so I placed the following in the User-defined key-bindings file:
[
{
"keys": ["alt+up"], "command": "swap_line_up",
"keys": ["alt+down"], "command": "swap_line_down"
}
]
The swap_line_down works but the swap_line_up doesn't. I've already checked for conflicts within Default(Windows).sublime-keymap. I've tried to swap the commands to check if the problem is specific with alt+up
[
{
"keys": ["alt+up"], "command": "swap_line_down",
"keys": ["alt+down"], "command": "swap_line_up"
}
]
and, indeed, now swap_line_up works but swap_line_down doesn't. So it seems alt+up is the problem. What seems to be the issue here?
Your key bindings aren't specified correctly; each binding object should have a single keys and command (and optionally a single args and context key s well), but you have both specified in a single binding.
It should look more like this:
[
{
"keys": ["alt+up"], "command": "swap_line_up",
},
{
"keys": ["alt+down"], "command": "swap_line_down"
},
]
In Sublime Text 3 is it possible to use C-x C-s for saving the file (save_all), while keeping C-s for search option?
ctrl+x+s or ctrl+xctrl+s did not work on my end.
{ "keys": ["ctrl+s"], "command": "find_next", "context":
[{"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}]
},
{ "keys": ["ctrl+x"], "command": "noop" },
{ "keys": ["ctrl+x+s"], "command": "save_all" },
{ "keys": ["ctrl+x+ctrl+s"], "command": "save_all" }
Binding key chords like this in Sublime requires you to specify both keys individually in the keys list (that's why it's a list).
So, what you want is:
{ "keys": ["ctrl+s"], "command": "find_next", "context":
[{"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}]
},
{ "keys": ["ctrl+x"], "command": "noop" },
{ "keys": ["ctrl+x", "ctrl+s"], "command": "save_all" },
Note that the binding of Ctrl+x to noop is not needed for this to work, so you can leave that out. However using the same key for both single items and in chords like this may require you to hit the key twice to get Sublime to trigger the command, since it otherwise can't tell without some delay which of the bindings you intended.
It is very useful that in ST3 you can copy a whole line with just ctrl+c, the only problem is that this command also copies the "return" or new line character, so for example when you copy a line and paste in a console it will run the command immediately. This is undesirable because I will want to first edit the command before running it. This forces me to manually highlight the line.
Is there a plugin or an easy way to cope the line where the cursor is without including the new line character?
You can replace the default behavior by creating a Sublime Text macro and a key bind for it on the Ctrl+C key:
Packages/User/SelectLineNoEOL.sublime-macro
[
{ "command": "move_to", "args": { "to": "hardbol" } },
{ "command": "move_to", "args": { "to": "eol", "extend": true } },
{ "command": "copy" },
]
Default.sublime-keymap
{ "keys": ["ctrl+c"], "command": "run_macro_file",
"args": {"file": "res://Packages/User/SelectLineNoEOL.sublime-macro"},
"context":
[
{
"key": "selection_empty", "operator": "equal",
"operand": true, "match_all": false,
},
],
},
I think I had saw another thread with a plugin which does this, but I could not find it.
Related threads:
forum#14576 How to disable selecting newline on triple click?
forum#14933 [ST3]Copy blank line using yy;p (Vi), paste one extra line
SUBJ.
I recently switched to Sublime from vim and trying to configure Sublime Text 3 in the way which I used to.
If I add binding, like below:
{ "keys": ["super+s"], "command": "exit_insert_mode", "context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
it switches mode to command, but do not save changes.
What you have specified overrides the existing save key binding, so it is behaving as expected. You will need to use a plugin or a macro to get the behavior you want. A macro would require you to save an additional file, so that's up to you. For a plugin solution, you should be able to use https://github.com/skuroda/ImprovedMacros to get the behavior you want. Replaying commands is based on some work I found on the ST forums. Never got around to finding a good way to record actions better though. That aside, there are install instructions in the README. I believe the following will work as your key binding with the plugin installed
{
"keys": ["super+s"], "command": "run_multiple_commands",
"args": {
"commands": [{
"context": "view",
"command": "save"
},{
"context": "view",
"command": "exit_insert_mode"
}]
},
"context": [
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
I am a vim user who is moving to Sublime text and using Vintage mode. In my .vimrc I have the following line:
imap jk <Esc>
In vim, this allows me to escape out of insert mode without having to lunge for the escape key and keep my fingers on the home row. How do I do the same thing with Sublime Text Vintage mode?
"Vintage mode is implemented entirely via key bindings and the plugin API - feel free to browse through the Vintage package and see how it's put together. As an example, if you'd like to bind "jj" to exit insert mode, you can add this key binding:"
{ "keys": ["j", "j"], "command": "exit_insert_mode",
"context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
Just modify first line to jk if you prefer that.
Source
If you are using the Vintageous plugin, use the following key binding:
{
"keys": ["j", "k"],
"command": "_enter_normal_mode",
"args": {"mode": "mode_insert"},
"context": [{"key": "vi_insert_mode_aware"}]
}
Also, Ctrl+[ works and is much easier to reach for than the esc key. This is in OSX at least.
For anyone using Neovintageous 1.22.0, you can set these options in Sublime Text preferences to remap <Esc>:
"vintageous_i_escape_jj": true
"vintageous_i_escape_jk": true
And that's it.
You don't need to add keys configuration into preference > settings but you need to add it into preferences > keybindings. Add the following code below:
{ "keys": ["j", "j"], "command": "exit_insert_mode",
"context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
Save the file. Test it, it should work.
https://www.sublimetext.com/docs/vintage.html#included