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
Related
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.
Is there any way to make sure that when holding down right/left arrow key, the cursor never goes past the current line? Just like Vim
Just add the following to your user keybindings:
{ "keys": ["left"], "command": "noop", "context": [
{ "key": "preceding_text", "operator": "regex_match", "operand": "^$" }
],
},
{ "keys": ["right"], "command": "noop", "context": [
{ "key": "following_text", "operator": "regex_match", "operand": "^$" }
]
},
This will override the default behavior for the left arrow key when the caret is at the start of the line, and for the right arrow key when the caret is at the end of the line, to call the noop command, which will perform no operation, instead of the usual movement command.
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 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 } ]
}
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 }
]
}