Related
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.
I want the output from my program to be printed on an empty terminal. ie, instead of,
PS C:\Stuff\More Stuff> & 'c:\Users\user\.vscode\extensions\ms-vscode.cpptools-1.4.1\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-w1d2d2zg.skd' '--stdout=Microsoft-MIEngine-Out-2q3w4dx4.xne' '--stderr=Microsoft-MIEngine-Error-sr0qr1un.pod' '--pid=Microsoft-MIEngine-Pid-zddzumbv.aaf' '--dbgExe=C:\Program Files\CodeBlocks\TDM-GCC-64\bin\gdb.exe' '--interpreter=mi'
Hello from my program
I want,
Hello from my program
Here is my launch.json if it's of any help,
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\CodeBlocks\\TDM-GCC-64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
}
So, is there a way to output the program into an empty terminal?
Edit: I found a similar question here, but the solution posted doesn't work for me. It says, "Property console is not allowed". I am using the f5 debugger to run my C++ programs. I found some other similar questions, but they don't have an answer.
For now, the best working solution I could find is running the following command at the start of the program.
int main()
{
cout << "\033[2J\033[1;1H";
/*rest of the code here*/
}
This clears the terminal before execution of the actual program. This will also clear any outputs from previous runs. I'd prefer to have my previous outputs.
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]
}
}
]
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 } },
]
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"
}
},