I would like to have ; inserted at the end of line, when I press ;; while in insert mode. What would be mapping for that in sublime-text 3?
Somtehing like:
inoremap ;; <C-o>A;
in VIM.
So far, I managed to get to EOL I am currently on, but have no idea on how to chain other command to insert ;. I was not able to find anything in documentation on running multiple commands in sequence.
{
"keys": [";", ";"],
"command": "move_to", "args": { "to": "eol" }
}
As I wasn't able to find any native-to-editor solution to this,
luckily there is a plugin called Chain of Command
https://packagecontrol.io/packages/Chain%20of%20Command
Then you can put this into user keymap settings file:
{
"keys": [";", ";"],
"command": "chain",
"args": {
"commands": [
[ "move_to", { "to": "eol" }],
[ "insert", { "characters": ";" } ]
]
},
// with a help of this line, command won't get executed
// if in command_mode (vintage mode enabled), so it applies to insert mode
// only.
"context": [ { "key": "setting.command_mode", "operand": false } ]
}
Related
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
I want to comment out pieces of code with one-line comments without using the arrows, like I do in IDEA, but Sublime Text 3 stays on the same line after commenting. How can I change this behavior?
The simplest solution is to use a Macro for this that combines together the commands for toggling a line comment and then moving the cursor, and then rebinding the key to run the macro.
Such a macro would look something like the following. Here this is saved as Packages\User\comment_line.sublime-macro.
[
{
"command": "toggle_comment",
"args": {"block": false }
},
{
"command": "move",
"args": {"by": "lines", "forward": true }
}
]
With this in place, you can add a binding such as the following to your custom key bindings:
{
"keys": ["ctrl+/"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/comment_line.sublime-macro"},
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": "true", "match_all": true },
]
},
If you change the name of the macro when you save it, that needs to be reflected here.
This binding includes a context that makes it only apply when there is no selection, in which case this binding will be ignored and Sublime will use the default instead.
That can be removed if you wish. However, WebStorm (the only JetBrains tool I have handy at the moment) operates in this fashion, so presuming that IntelliJ does as well this more accurately mimics what happens there.
Additionally, if you're mapping a different key to the comment command, make sure the original line is above the new addition:
{ "keys": ["ctrl+q"], "command": "toggle_comment", "args": { "block": false } },
{
"keys": ["ctrl+q"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/comment_line.sublime-macro"},
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": "true", "match_all": true },
]
},
There's a plugin called "Chain of Command" which can be found in here: https://github.com/jisaacks/ChainOfCommand
Once you have it installed, you can simply add the following to your key bindings:
{
"keys": ["super+forward_slash"],
"command": "chain",
"args": {
"commands": [
["toggle_comment", { "block": false }],
["move", { "by": "lines", "forward": true }]
]
}
}
I am using the keymap to execute the current line in sublime repl by hitting ctrl+enter. The cursor remains on the same line. What do I need to add to the keymap so the cursor would jump to the next line (as what happens in RStudio)?
[
{ "keys": ["ctrl+enter"], "command": "repl_transfer_current", "args": {"scope": "lines"}}
]
I found a way to do it using a python script plugin. Apparently, Sublime by default does not have the option of running multiple commands under a single keymap.
I used the method from here: https://forum.sublimetext.com/t/run-multiple-commands-command/6848
the steps are the following:
Sublime - Tools - Developer - New Plugin
copy code from run_multiple_commands.py found here: https://gist.github.com/bgmort/7ae52ea4270f1c404321c20d1b97733c#file-run_multiple_commands-py
and save the file under the same name as on github: run_multiple_commands.py
Sublime - Preferences - Key Bindings User
code:
{
"keys": ["ctrl+enter"],
"command": "run_multiple_commands",
"args": {
"commands": [
{ "command": "repl_transfer_current", "args": {"scope": "lines"} },
{ "command": "move", "args": {"by": "lines", "forward": true} }
]
}
}
or additionally add [ ] if the file is empty:
[{
"keys": ["ctrl+enter"],
"command": "run_multiple_commands",
"args": {
"commands": [
{ "command": "repl_transfer_current", "args": {"scope": "lines"} },
{ "command": "move", "args": {"by": "lines", "forward": true} }
]
}
}]
I've been trying to create a shortcut to the snippet palette in Sublime Text 3 but can't seem to get it to work. I don't get an error, I just get nothing. I am on a Mac and have the following in Preferences: Key Bindings - User
{
"keys": [ "ctrl+y" ],
"command": "show_overlay",
"args": {
"overlay": "command_palette",
"text": "Snippet:"
}
}
Did you put your code into this [] ?
It works for me:
[
{
"keys": ["ctrl+y"],
"command": "show_overlay",
"args": {
"overlay": "command_palette",
"text": "Snippet: "
}
}
]
I realized I use 'ctrl+enter' a lot more than 'enter' in ST3. Would it be possible to switch these two commands?
I can easily switch 'ctrl+enter' to 'enter' with:
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line.sublime-macro"} }
But I'm not sure how to switch 'enter' to 'ctrl+enter'. It seems that only the "auto-completion" functionality of 'enter' is defined in the default keymap.
{ "keys": ["enter"], "command": "commit_completion", "context":
[
{ "key": "auto_complete_visible" },
{ "key": "setting.auto_complete_commit_on_tab", "operand": false }
]
},
Any thoughts would be much appreciated!
PS. And if there was a way I could keep 'enter' to commit completion while also using it to skip to next line, that would be the icing on the cake.
Nevermind, I found it:
{ "keys": ["ctrl+enter"], "command": "insert", "args": {"characters": "\n"} },
That just leaves the question of how to continue to use 'enter' for auto-completion. If anyone has any ideas, I'd be curious to hear them!