In Sublime Text 2 - reopen build output - sublimetext2

In Sublimt Text 2, when I use the build system (make) to run tests, the output is displayed in the build output pane.
However, if I press escape to close the output pane (e.g. to make a fix), I can't find a way to redisplay the output pane to see what else was borked. Have tried to create a custom keybinding to execute show_panel "output", but can't get it working.
Meep?

The menu shortcut is under Tools -> Build Results -> Show Build Results.
I wish this was under the View menu like all the rest of view options...

As you can see in Packages/Default/Main.sublime-menu the command for "Show build results" is this:
{
"command": "show_panel",
"args": {
"panel": "output.exec"
},
"caption": "Show Build Results",
"mnemonic": "S"
},
so a custom key binding could be this:
{
"keys": ["ctrl+alt+super+r"],
"command": "show_panel",
"args": {
"panel": "output.exec"
}
}

And the key binding to hide the panel:
{
"keys": ["ctrl+shift+2"],
"command": "hide_panel",
"args": {
"panel": "output.exec"
}
},

Building on akirk's answer you can make it toggle the build results panel by copying some of the syntax used for the escape shortcuts.
Adding the following lines to the user key bindings will do part of the trick. As reported by some of the previous answers the hide_panel command will hide any panel, and pressing it a second time will reveal build_results.
{
"keys": ["alt+b"], "command": "show_panel", "args": {"panel": "output.exec"},"context":
[
{ "key": "panel_visible", "operator": "equal", "operand": false }
]
},
{
"keys": ["alt+b"], "command": "hide_panel", "args": {"panel": "output.exec"},"context":
[
{ "key": "panel_visible", "operator": "equal", "operand": true }
]
},

Related

How to bind a key for selected text in Sublime Text?

So I have a text for example "this is sample text" and I want it to become this "<![CDATA[this is sample text]]>"
I want to work this function like this: I select any text and use hotkey like ctrl+t or so.
I use Sublime Text 3.
How can I do this for the selection of text?
You can create a new keybinding to use the insert_snippet command to wrap your selection. (Preferences menu -> Keybindings)
{ "keys": ["ctrl+t"], "command": "insert_snippet", "args": {"contents": "<![CDATA[${0:$SELECTION}]]>"}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
]
},

Visual Studio Code snippet as keyboard shortcut key

I know how to modify and create code snippets and I know how to modify shortcut keys, but how does one bring those 2 together?
Note that the line below will open a list of snippets defined for the language you are currently using (and you don't want that)
"args": { "snippet": "'$TM_SELECTED_TEXT'" }
Whereas with the below line the snippet given as argument will be executed right away
"args": { "name": "your_snippets_name" }
Here's how I defined a snippet for HTML where I wanted to select a text and when pressing CTRL+B the text to become enclosed in <strong></strong> tags:
"make_strong": {
"prefix": "strong",
"body": [
"<strong>$TM_SELECTED_TEXT${1:}</strong>"
],
"description": "Encloses selected text in <strong></strong> tags"
}
Note the ${1:} above - what this does is that it places the cursor there. This enables you to press CTRL+B at cursor and then have the cursor placed inside the <strong></strong> tags. When selecting a string and pressing CTRL+B, the string will enclosed in <strong> tags and the cursor will be placed before the closing </strong> tag. Pressing TAB at this point, will put your cursor after the closing </strong> tag.
And added in my keybindings.json the following:
{
"key": "ctrl+b",
"command": "editor.action.insertSnippet",
"args": { "name": "make_strong" }
}
UPDATE JUNE 2nd, 2021
Since this is getting lots of views, I am posting some of the snippets I use, maybe it will be useful to someone
{
"key": "ctrl+alt+u",
"command": "editor.action.transformToUppercase"
},
{
"key": "ctrl+alt+l",
"command": "editor.action.transformToLowercase"
},
{
"key": "ctrl+b",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_strong" }
},
{
"key": "ctrl+i",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_italic" }
},
{
"key": "ctrl+u",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_underline" }
},
{
"key": "ctrl+alt+p",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_paragraph" }
},
{
"key": "ctrl+shift+space",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_nbsp" }
},
{
"key": "ctrl+enter",
"command": "editor.action.insertSnippet",
"args": { "name": "insert_br" }
},
It would seem that, as of version 1.9, Visual Studio Code can do what you are looking for, no other extensions necessary.
From https://code.visualstudio.com/updates/v1_9#_insert-snippets
"You can now bind your favorite snippets to key bindings. A sample that encloses a selection with single quotes looks like this:"
Add the snippet below to keybindings.json (open Keyboard Shortcuts editor and click on the For advanced customizations open and edit keybindings.json link)
{
"key": "cmd+k",
"command": "editor.action.insertSnippet",
"args": { "snippet": "'$TM_SELECTED_TEXT'" }
}
Here are 3 steps to create a code snippet along with a shortcut.
1. Code -> Preferences -> Keyboard Shortcuts
2. Click on icon for keybindings.json file
3. Add JavaScript objects for Code Snippet/Shortcuts
For example i have created snippets for logging purposes as I mostly work with JavaScript Frameworks.
1.console.log('') with shortcut Control (or Ctrl) ⌃ + l
2.console.warn('') with Control (or Ctrl) ⌃ + w
3.console.error('') with Control (or Ctrl) ⌃ + e
Code:
{
"key": "ctrl+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.log('${TM_SELECTED_TEXT}$1')$2"
}
},
{
"key": "ctrl+w",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.warn('${TM_SELECTED_TEXT}$1')$2"
}
},
{
"key": "ctrl+e",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.error('${TM_SELECTED_TEXT}$1')$2"
}
}
Call Command Palette in View menu
Hit "shortcuts json" and OK
Then append under code blocks
{
"key": "shift+alt+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus && editorLangId == 'js'",
"args": {
"snippet": "console.log($1);$0",
}
},
{
"key": "shift+alt+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus && editorLangId == 'dart'",
"args": {
"snippet": "print($1);$0",
}
},
If you press Shift+Alt+L in JavaScript then
put "console.log();" to your editor,
And press Shift+Alt+L in Dart then
put "print();" to your editor,
with the same shortcut.

In Sublime Text 3, how to have shortcuts for "Build and Run" and "Build only" separately like it was in Sublime Text 2?

In Sublime Text 3,when we press Ctrl+Shift+B, we are given the option to either do "Build and Run" or "only Build", whereas Ctrl+B executes the previously chosen operation among the two. But I want it to be like, it should directly build and run when I press Ctrl+Shift+B and only build when I press Ctrl+B like it was in Sublime Text 2. Can someone help me out?
Addings this to your sublime-keymap should result in the expected behavior:
{ "keys": ["ctrl+b"], "command": "build", "args": { "variant": "" } },
{ "keys": ["ctrl+shift+b"], "command": "build", "args": { "variant": "Run" } },
However you might want to remap keep the list of options to alt+b:
{ "keys": ["alt+b"], "command": "build", "args": { "select": true } },
Not answering the question but good to know, F7 functions the same as Ctrl+b.

Make ctrl+space more like Eclipse

In the Default (OSX).sublime-keymap file, I see:
{ "keys": ["ctrl+space"], "command": "auto_complete" },
{ "keys": ["ctrl+space"], "command": "replace_completion_with_auto_complete", "context":
[
{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
]
},
But I'd like it to function more like Eclipse, where methods available get popped up after hitting . and waiting for a split second. Is this possible?
Keep in mind that Sublime Text is not an IDE. As such, Eclipse like completion (where it only brings up methods that you can call for the particular variable) is not built in. You may try something like SublimeJava for completions more like Eclipse. I have used it a bit, with mixed results. It did not work as well as Eclipse, but for what I was doing, it was acceptable. To bring up your current set of completions (from within the file by default) when you press ".", you may add the following to your User Preferences (accessible through Preferences -> Settings - User).
"auto_complete_triggers": [{"selector": "source.java", "characters": "."}]
This will cause the auto complete pop up to be displayed when ever you enter . in java files.

Keyboard shortcut to comment lines in Sublime Text 2

In Sublime Text 2, how do I enclose a selection in a comment?
Is there a keyboard shortcut for this action?
By default on Linux/Windows for an English keyboard the shortcut is Ctrl+Shift+/ to toggle a block comment, and Ctrl+/ to toggle a line comment.
If you go into Preferences->Key Bindings - Default, you can find all the shortcuts, below are the lines for commenting.
{ "keys": ["ctrl+/"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+/"], "command": "toggle_comment", "args": { "block": true } },
In the "Preferences->Key Bindings - User"
[
{ "keys": ["ctrl+7"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+7"], "command": "toggle_comment", "args": { "block": true } }
]
Just paste it, these are will work great !
I'd like to add, that on my mac by default block comment toggle shortcut is cmd+alt+/
For German keyboards use ctrl+shift+# to toggle a block comment and ctrl+# to toggle a line comment.
The shortcut in Preferences->Key Bindings - Default is set to Ctrl+Shift+/ and Ctrl+/, but to actually use the functions, press the keys stated above.
In a Brazilian Portuguese ABNT2 keyboard I have a similar issue to the one reported by JoshDM. In the file sublime-keymap I have:
{ "keys": ["ctrl+/"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+/"], "command": "toggle_comment", "args": { "block": true } },
But I have to use ctrl+; and ctrl+shift+;. On my keyboard, ; is on the left of /.
It seems like a bug.
you need to replace "/" with "7", it works on non english keyboard layout.
This did the trick for me coming from Brackets and being used to ctrl+/ on the numpad.
[
{ "keys": ["ctrl+keypad_divide"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+keypad_divide"], "command": "toggle_comment", "args": { "block": true } }
]
In my keyboard (Swedish) it´s the key to the right of "ä": "*".
ctrl+*
In keyboard (Spanish), SO: Win7.
Go into Preferences->Key Bindings - Default,
replace..."ctrl+/"]... by "ctrl+7"...
And don't use the numpad, it doesn't work.
Just use the numbers above the letters
On a Mac with a US keyboard, you want cmd+/.
Seems like some kind of keyboard mapping bug. I'm Portuguese, so I'm using a PT/PT keyboard. Sublime Text 3 apparently is handling / as ~.
Max OS: If you want to toggle comment multiple individual lines versus block comment an entire selection, you can do multi line edit, shift+cmd+L, then cmd+/ in that sequence.
First Open The Sublime Text 2.
And top menu bar on select the Preferences.
And than select the Key Bindings -User.
And than put this code,
[
{ "keys": ["ctrl+shift+c"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+c"], "command": "toggle_comment", "args": { "block": true } }
]
I use Ctrl+Shift+C, You also different short cut key use.
Ctrl+d and Ctrl+Shift+d....
[
{ "keys": ["ctrl+d"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+d"], "command": "toggle_comment", "args": { "block": true } },
]
On my laptop with spanish keyboard, the problem seems to be the "/" on the key binding, I changed it to ctrl+shift+c and now it works.
{ "keys": ["ctrl+shift+c"], "command": "toggle_comment", "args": { "block": true } },