Set custom hotkeys on indent/unindent in Sublime Text 3 - sublimetext

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

Related

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

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.

VSCode - how to add more keybindings to the integrated terminal

I have managed to add a few keybindings to the integrated terminal of VSCode, but want to add more. How can I add my own keybindings?
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "cmd+right", "command": "workbench.action.terminal.focusNext",
"when": "terminalFocus" },
{ "key": "cmd+left", "command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus" },
{ "key": "cmd+delete", "command": "workbench.action.terminal.deleteAllRight",
"when": "terminalFocus" }
]
The first two work, but the last one does not, and I'm guessing this is due to the fact that the integrated terminal does not have this option. Is there a way to add it? I want to have all my regular terminal keybindings here as well.
{
"key": "cmd+x",
"command": "workbench.action.terminal.kill",
"when": "terminalFocus"
}
You probably know this one already, but just in case. It only kills the current terminal but you could press it a few times for the same functionality.

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

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

How to create a keyboard shortcut for SublimeREPL

I am new to Sublime Text 2 on Mac OS.
I installed the package SublimeREPL.
Is it possible to create a keyboard shortcut to run the file with SublimeREPL?
More precisely, here is a screenshot. I want to avoid going through this menu and run quickly with a keyboard shortcut.
You can set a keyboard shortcut for the command in your screenshot using Sublime key-bindings.
Open Sublime.
Go to Preferences > Key Bindings - User
Add these lines to the opened file between brackets:
{ "keys": ["ctrl+alt+b"], "command": "run_existing_window_command", "args":
{
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}}
Save it.
It's done! You can type any key-combinations instead of "ctrl+alt+b", but make sure it's not reserved by Sublime itself (check in Preferences > Key Bindings - Default)
You can set keyboard shortcuts for any menu item that you can select, in any app.
Go to System Preferences → Keyboard → Shortcuts → App Shortcuts
Click the + to add a new shortcut.
Set the Application to Sublime Text.app, the Menu Title to the exact name of the menu option, and choose a Keyboard Shortcut.
Click Add.
I found that I lost the keybinding to the installed sublimeREPL, so I had to find how to get it back, since it is a time saving indispensable for me. I used it also on a pc that had not sublime Repl and worked for both. This worked for me in 2019, version 3.2
in preferences / keybinding (after you installed package control and sublimeREPL). I made this video too.
[
{"keys": ["ctrl+b"], "command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["C:/Users/giova/AppData/Local/Programs/Python/Python37-32/python.exe", "-u", "-i", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}}
]
p.s.: change the location of the python.exe as it is stored in your pc.
You can also do this:
[
{"keys": ["ctrl+b"], "command": "repl_open",
"caption": "Python - RUN current file",
"id": "repl_python_run",
"mnemonic": "s",
"args": {
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"cmd": ["py", "-u", "-i", "$file_basename",],
"type": "subprocess",
"encoding": "utf8",
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"view_id": "*REPL* [python]",
}}
]
To use different version of python, you can type py -2.7 for example, if you have them installed.
You can also use 'python' in the cmd list.
To see where the location of python is, you can import sys and look at sys.path from python itself. You can also add "-m", "-pdb" to do the debugging, using another key combination maybe.
This works again in 3.2
[
{ "keys": ["ctrl+b"], "command": "run_existing_window_command", "args":
{
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}}
]
Go to Preferences -> Key Bindings, and write this in the window "Sublime-keymap --User"
[
{
"keys": ["ctrl+alt+b"],
"command": "repl_open",
"args": {
"cmd": ["python", "-u", "-i", "$file_basename"],
"cwd": "$file_path",
"encoding": "utf8",
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"external_id": "python",
"syntax": "Packages/Python/Python.tmLanguage",
"type": "subprocess"
}
}]
i have an addition to Romina's answer,
i used her code, but it opens with Python default version, in my case (Linux Mint) it was Python 2.7,
so if you have that trouble just change her code with this:
[
{
"keys": ["ctrl+alt+b"],
"command": "repl_open",
"args": {
"cmd": ["python3", "-u", "-i", "$file_basename"],
"cwd": "$file_path",
"encoding": "utf8",
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"external_id": "python3",
"syntax": "Packages/Python/Python.tmLanguage",
"type": "subprocess"
}
}]
And it works with Python 3 (if you have it installed of course)
tq, add debug
{ "keys": ["ctrl+b"], "command": "run_existing_window_command", "args":
{
"id": "repl_python_pdb",
"file": "config/Python/Main.sublime-menu"
}
},

Resources