How to select a line without selecting the line break at the end of it in Sublime Text? - sublimetext

When I click on the line number at the left or if I triple click the text in the line, I don't want the following new line/line break to be selected. Is there any simple way to change the settings for this? It would save a lot of time when copying/pasting.

This won't help with clicking on the line number, but here's how you can change the triple-click. In Default (Windows).sublime-mousemap, the triple-click is defined like this:
// Drag select by lines
{
"button": "button1", "count": 3,
"press_command": "drag_select",
"press_args": {"by": "lines"},
},
You can override that definition by creating a corresponding Default (Windows).sublime-mousemap file in your User package, and then redefine it like this:
[
// Drag select by lines
{
"button": "button1", "count": 3,
"press_command": "drag_select",
"press_args": {"by": "lines"},
"command": "move",
"args": {"by": "characters", "extend": true, "forward": false}
},
]
Note: The press_command/press_args lines are what happens on the button's way down (the third time in this case). Adding the command/args lines tells it what to do when the button comes back up.
Likewise, you can define an alternative to the Expand Selection to Line command keybinding (ctrl+L) in your User\Default (Windows).sublime-keymap:
{ "keys": ["alt+l"], "command": "chain", "args": {
"commands": [
["expand_selection", {"to": "line"}],
["move", {"by": "characters", "extend": true, "forward": false}],
]
}
}
In this case, you can't have two command/arg lines directly in the same binding, so we go through the "chain" command.

Related

How can I set the ruler in sublime from the command palette/hotkey?

I can do this by clicking View -> Ruler -> 80 but it'd be a lot more convient to do it from the command palette or a hotkey (apart from alt, right, right, right, right, down, down, down, down, down, down, down, down, down, down, down, down, down, down, down, down, down, down, right, down, down, down, enter).
Edit: Though I found a way to make a file to add command palette options, I do not know how to make it work for arbitrary numbers, ideally typing set ruler 33 would set the ruler to 33 and set ruler 44 66 would make a ruler at 44 and 66. I only know how to do it by making an explicit command for each value rather than a dynamic one for all of them.
Once you have the menu bar focused, you can generally hit the first letter of a menu to open it (V for View in this case), then the first letter of any submenus or options you wish to open or select, respectively. In previous versions of Windows (I haven't used Win10 yet) there was an option, usually set by default, to underline the "hotkey" of the menu item, which is especially useful if you have two menu items that begin with the same letter. If nothing is underlined, I would assume you can just start spelling out the menu item, so if you have View and Verify on the same submenu, you'd just type vi for the first and ve for the second one.
So, for your particular setup, just hit Alt to focus the menu bar, then V, R, 8 for View -> Ruler -> 80, respectively.
As a freebie, I'll give you not one but two keyboard shortcuts as well:
{
"keys": ["ctrl+shift+8"],
"command": "set_setting",
"args":
{
"setting": "rulers",
"value": [80]
}
},
{
"keys": ["ctrl+shift+0"],
"command": "set_setting",
"args":
{
"setting": "rulers",
"value": []
}
}
Add these to your user keymap, and CtrlShift8 will set the rulers to 80, while CtrlShift0 will set them back to none. Remember that this is for the current view only, not all open files, and any newly-opened files or views will default back to the value in either your project, user settings, or default settings (in that order).
It turns out making a file to add command line palette items is actually pretty easy! Make a file called ruler.sublime-commands and place it in the Installed Packages folder (differs by OS, on windows it is C:\Users\<you>\AppData\Roaming\Sublime Text 3\Installed Packages).
With the below content you can open the palette and type ruler 80 or unset ruler.
[
{
"caption": "View: Unset Ruler",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": []
}
},
{
"caption": "View: Set Ruler: 70",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [70]
}
},
{
"caption": "View: Set Ruler: 72",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [72]
}
},
{
"caption": "View: Set Ruler: 78",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [78]
}
},
{
"caption": "View: Set Ruler: 80",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [80]
}
},
{
"caption": "View: Set Ruler: 100",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [100]
}
},
{
"caption": "View: Set Ruler: 120",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [120]
}
}
]

Set custom hotkeys on indent/unindent in Sublime Text 3

In VIM I'm using Shift+> and Shift+< for indent/unindent code blocks, but this shortcut doesn't works in my ST3 (Mac OS X preferences). How I can solve this issue?
By default at preferences:
{ "keys": ["super+]"], "command": "indent" },
{ "keys": ["super+["], "command": "unindent" },
And my preferences file contains this line:
{ "keys": ["shift+>"], "command": "indent" },
{ "keys": ["shift+<"], "command": "unindent" },
The problem is there is no such combination as shift+<. To get to the bracket character, you are actually pressing Shift and comma (shift+, = <). So, all you have to do is use the bracket characters < and > in your keymap file.
{ "keys": [">"], "command": "indent" },
{ "keys": ["<"], "command": "unindent" }

Sublime Text 3 Windows column selection with Alt?

Shift + right-click feels unintuitive to me.
How can I tell ST3 to allow Alt + drag to do column selection, like in many other programs?
I got this to work on Windows 7 using Sublime Text 3.
I created a file "C:\Users\\AppData\Roaming\Sublime Text 3\Packages\User\Default (Windows).sublime-mousemap", and put this in it:
[
{
"button": "button1","modifiers": ["alt"],
"press_command": "drag_select",
"press_args": {"by": "columns"}
},
]
The accepted answer by dwn is correct, but it is not complete answer.
This is more complex, because sometimes you need select two columns or just unselect some.You need something like this:
[
{
"button": "button1", "modifiers": ["alt"],
"press_command": "drag_select",
"press_args": {"by": "columns"}
},
{
"button": "button1", "modifiers": ["alt", "shift"],
"press_command": "drag_select",
"press_args": {"by": "columns", "additive": true}
},
{
"button": "button1", "modifiers": ["alt", "ctrl"],
"press_command": "drag_select",
"press_args": {"by": "columns", "subtractive": true}
}
]
Tested on Win 7 and Sublime Text 3

Add # comments on block with Sublime text 2

I would like to know the steps to add # comments on a block with sublime.
basically to go from a code like this
console.log "code here"
console.log "code there"
Apply the short-cut, then obtain a code like this
# console.log "code here"
# console.log "code there"
Right now I can only remove them with the multiple cursor Ctrl+D.
The traditional Ctrl+/ or Ctrl+Shift+/ doesn't work because it provides a comment like this :
//console.log "code here"
//console.log "code there"
You can create a macro
[
{"command": "split_selection_into_lines"},
{"command": "move_to", "args": {"to": "bol", "extend": false}},
{"command": "insert", "args": {"characters": "# "}}
]
Then a keymapping:
{ "keys": ["ctrl+shift+i"], "command": "run_macro_file", "args": { "file": "Packages/User/Snippets/test_snippets/tmp_comment.sublime-macro" } }
CTRL+/ for line comment
CTRL+Shift+/ for block comment

Sublime Text: How to set up begining of line/end of line shortcuts to match the shell?

I've been using Sublime Text for a little while now (on MacBook Pro), and want to make it keystroke compatible with the shell.
In the shell, to jump to the beginning/end of line I press fn+Left/fn+Right.
In Sublime Text, I understand how to set up key bindings for fn+Left/fn+Right, but I see no key name for the fn key (not the f1, f2, etc. function keys, I am referring to the key marked "fn").
How can I make this work in Sublime Text?
I guess I was making it too hard on myself.
the fn button does not have a key name in Sublime Text.
fn+Left/fn+Right is read as Home/End. Simply mapping Home and End did the job.
Specifically:
Sublime Text | Preferences | Key Bindings - User
Add the following between the [ ]:
{ "keys": ["home"], "command": "move_to", "args": { "to": "hardbol" } },
{ "keys": ["end"], "command": "move_to", "args": { "to": "hardeol" } }
I discovered this by opening up the SublimeText console:
ctrl+`
sublime.log_input(True)
Now, typing any keys reveal their Sublime Text key names. fn did not elicit a response, but fn+Left/fn+Right yielded Home/End.
sublime.log_input(False)
Hope that helps.
For me(on MBP):
cmd and left worked as Home
cmd and Right worked as End
Without changing any configuration in Preferences.
Open menu Sublime Text > Preferences > Key Bindings
Add the following to the array (between square brackets []):
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
{ "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} },
{ "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true } }
You can now use the following combinations:
Go to beginning of line: Home
Go to end of line: End
Select from cursor position to beginning of line: ⇧+Home
Select from the cursor position to end of line: ⇧+End
For adding the keybindings to ST4 on Macbook Pro (to match the windows ones with home and end), this worked
[
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
{ "keys": ["ctrl+home"], "command": "move_to", "args": {"to": "bof"} },
{ "keys": ["ctrl+end"], "command": "move_to", "args": {"to": "eof"} },
{ "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} },
{ "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true } },
{ "keys": ["ctrl+shift+end"], "command": "move_to", "args": {"to": "eof", "extend": true} },
{ "keys": ["ctrl+shift+home"], "command": "move_to", "args": {"to": "bof", "extend": true } },
]

Resources