"Close tabs in current pane" command for Sublime Text 2 - command

Like many others, I use panels extensively in Sublime Text 2 (View->Layout->etc).
I'd like to map a shortcut to close all tabs in the active panel.
I know the close_alland close_others commands exist as documented in the following SO questions:
Close all tabs, but not the window, in Sublime Text
"Close Others" command shortcut in Sublime Text 2
However, I haven't been able to find a command to close just the tabs in the active pane.
Is there a way to do this?

Make a file in your Packages/User directory named closetabsinpane.py with these contents:
import sublime
import sublime_plugin
class CloseViewsInGroupCommand(sublime_plugin.WindowCommand):
def run(self):
for v in self.window.views_in_group(self.window.active_group()):
g, view_index = self.window.get_view_index(v)
self.window.run_command("close_by_index", { "group": g, "index": view_index})
And add a shortcut to your user keymap file:
{ "keys": ["ctrl+shift+alt+x"], "command": "close_views_in_group" },

Related

How to make vscode call snippet from shortcut keybindings instead of asking user to 'select a snippet'?

An hour ago, my snippets and keybindings were working in VSCode. I must have changed a setting on accident?
Problem:
When I use custom keyboard shortcuts to call custom snippets, the snippet does not run. Instead, vscode provides a dropdown menu with all of my snippets (those with and without keybindings) and asks me to select one. But I shouldn't have to select one - the keybinding already 'knows' which snippet it should have ran.
How can I make my snippet run again with the keyboard shortcut?
{
"example snippet": {
"prefix": "ex",
"body": "const example = `${1:exampleText}`",
"description": "Example: exampleText"
}
}
When I type ex + tab in my editor - it works.
Here is my keybinding
{
"key": "ctrl+e ctrl+x",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"arg": {
"name": "example snippet"
}
}
But when I press ctrl e x, a dropdown appears asking to select my snippet.
How do I fix this behavior? It only asks me to select a snippet if the keyboard shortcut points to a snippet. For example, when I press Ctrl+C, this drop-down does not appear. It knows it is a snippet, but it thinks it doesn't know which snippet!

Visual studio code - shortcut to open next file by name

I often find myself working on file test-1a.robot and I want to open test-1b.robot, which is the next alphabetical file in the editor list.
With the files are open and I have a "sort tabs" extension enabled I can use ctrl+pgup and ctrl+pgdn which is already something, but I'd like to have it even without the tab sorting or opening files in advance.
Maybe you need to train yourself in the following key combo:
Ctrl+Shift+E DownArrow Enter
I tried to use multi-command to create a combo of
show explorer tab
go to next file down
open this file
For (1.) I could find a command, it sets the focus on the current file in the Explorer.
Edit With the tip from mark for the commands to type the cursor down (2) and select command (3) in listboxes.
You can add this to your settings and create a key binding for this new command
"multiCommand.commands": [
{
"command": "multiCommand.openNextABCFile",
"sequence": [
"workbench.view.explorer",
"list.focusDown",
"list.select"
]
}
]
It opens the next alphabetical filename in preview mode.

VSCode keyboard shortcut to navigate from search bar to highlighted selection

I'm constantly searching code within a file in VSCode.
Is there a keyboard shortcut to navigate from the search bar to the highlighted selection in the editor? That would make things much more efficient for me.
I know I can copy a highlighted selection from the editor to the search bar using CMD + F.
If you are talking about moving from the find widget to the first match, it looks like you have this option, assuming you don't want to just close the find widget with escape:
the workbench.action.focusActiveEditorGroup command is unbound you could use that. But you have to hit escape twice to unselect the find match if you don't want it to remain selected.
That's a pain though so you might a macro that does it all at once. Like (in settings):
"multiCommand.commands": [
{
"command": "multiCommand.focusEditorFromFind",
"sequence": [
"workbench.action.focusActiveEditorGroup",
"cancelSelection",
"cancelSelection",
]
}
]
and keybindings.json:
{
"key": "shift+e",
"command": "multiCommand.focusEditorFromFind",
"when": "editorFocus && findWidgetVisible"
}
So after typing your find term, just Enter until you get to the particular find match you want to switch focus to, and the Shift+E or whatever keybinding you go with above.
Maybe I am just missing it but it seems odd there isn't an easier way to toggle focus from the find widget.

How to Create Custom Key Binded Snippets in VS Code

I am a huge Sublime Text user, and learned ways to improve my productivity using customizations in Sublime text. But as VScode is becoming popular day by day, wanted to check if there is any way which I can bind the shortcut keys to the custom actions.
For example, I select a word ABC in any file in VSCode and hit CTRL+B, and it places my own defined values around it like it should become
<b>ABC</b>
I had created the following snippet in Sublime Text, which when I wrote in Visual Studio Code - keybindings.json nothing worked.
{
"keys": [
"ctrl+b"
],
"command": "insert_snippet",
"args": {
"contents": "<b>${0:$SELECTION}</b>"
}
}
This will work in your keybindings.json:
{
"key": "ctrl+b",
"command": "editor.action.insertSnippet",
"when": "resourceExtname == .html", // this is optional
"args": {
"snippet": "<b>${TM_SELECTED_TEXT}</b>"
}
},
The optional when clause is if you want to limit the snippet's operation to .html files.
More general though is to use the emmet command which is built-in: Emmet: Wrap with Abbreviation in the command palette. Select your text, open the command palette, find that command and trigger it - type b or whatever your element is and it will wrap the selected text with the opening and closing elements.
[Note that there is a command workbench.action.toggleSidebarVisibility already bound to Ctrl-B, but the snippet above version seems to take precedence - meaning you lose the toggleSidebarVisibility keybinding functionality - that may be acceptable to you?]

How to create macro in sublime text 3 with saveAs and close file command?

I need to change encoding of a lot of html files to UTF8 (from Windows 1252). I´m using Sublime text 3 on Windows 8. So I think creating macro will be very efficient, I need just two commands in that macro "Save with Encoding - UTF8" and "Close file". But when I´m trying to record macro these commands are not recorded. So I need to manually create json file with macro command but I don´t know how.
I'm not sure that this can be done with a macro maybe these commands are out of scope for a macro (eg a window command not a view command?), but I managed to make it work as a plugin…
Save the following as $PATH_TO_SUBLIME_DATA/Packages/SaveAs-UTF8.py
import sublime, sublime_plugin
class SaveAsUtf8Command(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("save", {"encoding": "utf-8" })
self.window.run_command("close")
To trigger the command with 'Command Option Shift 8', add the following to your Sublime Text > Preferences > Keybindings - User file:
[
{ "keys": ["super+option+shift+8"], "command": "save_as_utf8"}
]
I've saved this as a gist if you prefer: https://gist.github.com/9505499