Make cursor not scroll past line in Sublime text 3 - sublimetext3

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.

Related

In Sublime Text how to copy line without end of line character

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

How to make Sublime Text 3 to move the cursor to the next line after ctrl + / comment?

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 }]
]
}
}

How to make a key binding that will jump over the code completion in sublime unless it's a {} or []

I found a great keybinding that jumps over sublimes code compeletion by hitting enter here's the link: quora. My code in my keymap file is:
// BEGIN keymaps for skipping to the end of " ) and ] code compeletion
{ "keys": ["enter"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)'\"\\]]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
// END keymaps for skipping to the end of " ) and ] code compeletion
and it defintely works how I'd like...most of the time. For example if I'm typing in some javascript:
function(p1, p2|)|
hitting enter..^.^
and I hit enter when the cursor is at the first carrot then it will jump over to the second carrot which is what I want. However, there's another case which is when you open up, say square brackets in a sublime settings file.
[|]|
.^.^
Now because of the keymapping the cursor jumps over the right square bracket, when in reality what you want is to insert a new line like:
[|
.^
|
....^
]
and move the carrot from the first to the second carrot, just like the behavior that happens when you create a javascript function:
function myFunction(){|
| <-- cursor tabbed over
} <--curly on bottom
My problem is I don't really understand regex that well yet, or how to use them in combination with keymaps in sublime. Really what I need to figure out (I think) is how to insert some sort of conditional into the keymap that basically just checks:
if (next char is a ] and the char before it is a [)
then don't do any completion hoping
else do exactly like the keymap is already set up to do
How would I go about doing this? Thanks for your help :)
If I understand your question correctly, you want the functionality to work when the cursor is inside parentheses () but not when inside square brackets []. If that's the case, simply change this line:
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)'\"\\]]", "match_all": true },
to this:
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)'\"\]", "match_all": true },
All I did was change the "operand" from this
"^[)'\"\\]]"
to this
"^[)'\"\]"
by removing
\]

Pop-up spelling suggestions context menu with spell checking in Sublime Text 3

I have coded a keybinding the the context menu with:
command: context_menu
to see the spelling suggestions but do to the way it goes to the next word and puts the cursor at the end of the word thid doesn't work. But if the cursor is inside the word or at the beginning of the word it does work. Is there an easy way to say go back one character then bring up the context menu?
Also is it possible to get ctrl+n and ctrl+p working in the context menu. Assume the context menu has the default bindings turned off.
Ended up using the suggestion of the answer below but just slightly different solution to bring you back to the beginning of the word after the command is run I did this:
{
"keys": ["ctrl+alt+w"],
// Force ability to bring up context menu
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "equal", "operand": true } ],
"args": {
"commands": [
// ["move", {"by":"word", "forward": false, "extend": false}],
["sbp_move_word", {"direction": -1}],
["context_menu"],
["move", {"by":"wordends", "forward": true, "extend": false}],
] }
},
// Do not use "find_under_expand" if selection is made
{
"keys": ["ctrl+alt+w"],
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "equal", "operand": false } ],
"args": { "commands": [
["sbp_move_word", {"direction": -1}],
// ["move", {"by":"word", "forward": false, "extend": false}],
["context_menu"],
["move", {"by":"wordends", "forward": true, "extend": true}],
] }
},
For some reason I had problems using the regular move command but should work fine too so commented it out above the sublemacs one:
[1]
Install:
Chain Of Command
[2]
Add this to your key bindings:
// Use "find_under_expand" if no selection is made
{
"keys": ["ctrl+super+alt+t"],
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "equal", "operand": true } ],
"args": {
"commands": [
["find_under_expand"],
["select_word_beginning"],
["context_menu"],
] }
},
// Do not use "find_under_expand" if selection is made
{
"keys": ["ctrl+super+alt+t"],
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "not_equal", "operand": true } ],
"args": {
"commands": [
["select_word_beginning"],
["context_menu"],
] }
},
The find_under_expand command will select the word at the caret, which enables context_menu to consistently execute with spelling suggestions.
The second key-binding does not utilize find_under_expand, as this would cause multiple instances of your already selected text to be selected.
[3]
Save this as SelectWordBeginnings.py somewhere in your /Packages/ directory:
import sublime, sublime_plugin
class SelectWordBeginningCommand ( sublime_plugin.TextCommand ):
def run ( self, edit ):
view = self.view
selections = view.sel()
if len ( selections ) == 0:
return
selection = selections[0]
if selection.a < selection.b:
newSelection = sublime.Region ( selection.b, selection.a )
view.selection.clear()
view.selection.add ( newSelection )
This command will invert selected regions so the caret is always at the beginning of the word.

Deselect text in sublime text vintage mode without escape key

In Sublime Text 2, I use the escape key to deselect text. In vintage mode, this also maps to command mode with the result that I am always unintentionally entering command mode.
How do I either:
Deselect text using a different key than escape
-OR-
Replace the escape key mapping to command mode with something else
You can use other keys to exit insert mode by changing C:\Users\lhuang\AppData\Roaming\Sublime Text 2\Packages\Vintage\Default.sublime-keymap. For example, I use double ; to exit insert mode.
{ "keys": [";", ";"], "command": "exit_insert_mode",
"context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
},
{ "keys": [";", ";"], "command": "exit_visual_mode",
"context":
[
{ "key": "setting.command_mode"},
{ "key": "num_selections", "operand": 1},
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": false }
]
},

Resources