Enable spectacle keybindings with sublime text 2 on OSX Mavericks - sublimetext2

I'm using spectacle on Mavericks (OSX 10.9). The default keybinding is super + alt + left pushes your current window to the left side of the screen and super + alt + right pushes your current window to the right side of the screen. This works great with most of my applications, except from sublime text 2. I tried to change the default sublime text keybindings by removing the following lines:
{ "keys": ["super+alt+left"], "command": "prev_view" },
{ "keys": ["super+alt+right"], "command": "next_view" },
but I'm still unable to use spectacle appropriately to move my sublime editor around my screen.
Any tips? Thanks

Same problem. According to the official website, the default key binding could be modified by overwrite default ones in your own (User) config file via "Preference -> Key Biding" menu, and I tried nullify the view switching behavior with
[
{ "keys": ["super+alt+left"],"command":"noop"},
{ "keys": ["super+alt+right"],"command": "noop"}
]
This doesn't work because it basically ignored the key-combo press, rather than passing over the registered key press to other Applications (Spectacle in this case).
One potential solution is to change the Spectacle key binding, but I don't want to.

Related

How to do tag wrapping in VS code?

I would like to wrap my selected html within a tag in VS code.
How do I do that?
Embedded Emmet could do the trick:
Select text (optional)
Open command palette (usually Ctrl+Shift+P)
Execute Emmet: Wrap with Abbreviation
Enter a tag div (or an abbreviation .wrapper>p)
Hit Enter
Command can be assigned to a keybinding.
This thing even supports passing arguments:
{
"key": "ctrl+shift+9",
"command": "editor.emmet.action.wrapWithAbbreviation",
"when": "editorHasSelection",
"args": {
"abbreviation": "span",
},
},
Use it like this:
span.myCssClass
span#myCssId
b
b.myCssClass
A quick search on the VSCode marketplace: https://marketplace.visualstudio.com/items/bradgashler.htmltagwrap.
Launch VS Code Quick Open (Ctrl+P)
paste ext install htmltagwrap and enter
select HTML
press Alt + W (Option + W for Mac).
As I can't comment, I'll expand on Alex's fantastic answer.
If you want the Sublime-like experience with wrapping, open up the Keyboard Shortcuts (command ⌘/Ctrl+shift+P > Preferences: Open Keyboard Shortcuts (JSON)) and add the following object:
{
"key": "alt+w",
"command": "editor.emmet.action.wrapWithAbbreviation",
"when": "editorHasSelection && editorTextFocus"
}
Which will bind the Emmet wrap command to option
⌥/Alt+W when text is selected.
You can also use the UI to do this, open the Keyboard Shortcuts menu and search for "emmet wrap with abbreviation" to add the shortcut.
Open Keyboard Shortcuts by typing ⌘ Command+k ⌘ Command+s or Code > Preferences > Keyboard Shortcuts
Type emmet wrap
Click the plus sign to the left of "Emmet: Wrap with Abbreviation"
Type ⌥ Option+w
Press Enter
imo there's a better answer for this using Snippets
Create a snippet with a definition like this:
"name_of_your_snippet": {
"scope": "javascript,html",
"prefix": "name_of_your_snippet",
"body": "<${0:b}>$TM_SELECTED_TEXT</${0:b}>"
}
Then bind it to a key in keybindings.json E.g. like this:
{
"key": "alt+w",
"command": "editor.action.insertSnippet",
"args": { "name": "name_of_your_snippet" }
}
I think this should give you exactly the same result as htmltagwrap but without having to install an extension.
It will insert tags around selected text, defaults to <b> tag & selects the tag so typing lets you change it.
If you want to use a different default tag just change the b in the body property of the snippet.
With VSCode 1.47+ you can simply use OPT-w for this.
Utilizing built-in functionality to trigger emmet, this is the easiest way:
Select your text/html.
Shift+Option+w
In the emmet window opened in the command palette, type in the tag or wrapping code you need.
Enter
Voila
Many commands are already attached to simple ctrl+[key], you can also do chorded keybinding like ctrl a+b.
(In case this is your first time reading about chorded keybindings: They work by not letting go of the ctrl key and pressing a second key after the first.)
I have my Emmet: Wrap with Abbreviation bound to ((ctrl) (w+a)).
In windows: File > Preferences > Keyboard Shortcuts ((ctrl) (k+s))> search for Wrap with Abbreviation > double-click > add your combonation.
I just installed htmltagwrap from extension marketplace and used ALT-W to wrap the tags (Windows Version).
There is a fast typing of the solution.
Open the command palette (usually Ctrl+Shift+P)
Preferences: Open Keyboard Shortcuts (JSON)
Add this snap code
{
"key": "ctrl+`",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "~~${TM_SELECTED_TEXT/^([\\t]*).*$/$1/}${TM_SELECTED_TEXT/^[\\t]*(.*)$/$1/}${TM_SELECTED_TEXT/^([\\t]*).*$/$1/}~~"
},
}
You select any text and press ctrl+`
result:
~~YourText~~

How do I insert a snippet of text using a keyboard shortcut in Sublime Text?

How do I set a shortcut for inserting console.log() and wrapping it around my current selection in Sublime Text without installing any plugin or extra third-party stuff?
So I found the answer. Thought I'd add it here for others:
Go to Sublime Text 2 > Preferences > Key Bindings - User and add this JSON to the file:
[
{ "keys": ["alt+d"],
"command": "insert_snippet",
"args": {
"contents": "console.log(${1:}$SELECTION);${0}"
}
}
]
Inserts a console.log() at the current cursor position on pressing alt+d.
Reference: https://gist.github.com/harthur/2951063

Bind command show_at_center to space bar in Sublime Text 2

In vim, in command mode, I'm quite fond of using the space bar to center the current line on screen. nmap <space> zz maps this functionality to the space bar in my gvimrc file. I'm trying to bind the same functionality to the space bar in Sublime Text 2:
{ "keys": ["space"], "command": "show_at_center", "args": {"command_mode": true} }
The line above doesn't work. Can anyone tell me why, and what will? I have Sublime's Vintage mode enabled. Also, I have “scroll_past_end”: true in my Sublime Text 2 User Preference Settings so that even the last lines of a file can be centered.
Try adding the following to Packages/User/Vintage/Default (<your OS>).sublime-keymap:
{ "keys": ["space"], "command": "show_at_center",
"context":
[
{ "key": "setting.command_mode"}
]
}
I can't test it right now, but it should work :)
EDIT - it doesn't. See below...
UPDATE
So I've searched far and wide, and it seems that, for whatever reason, you cannot assign an action to space on its own. Assigning it to Altspace works just fine:
{ "keys": ["alt+space"], "command" : "center_on_cursor",
"context": [{"key": "setting.command_mode"}] }
as does assigning it to a function key (F7, for example), or even to a single letter, like M. However, space on its own only results in the cursor moving one character forward when in command mode. The good news is that hitting z,z (lowercase) whilst in command mode will do what you originally wanted to do, which is center the cursor (as does CtrlL, as you indicated). Unfortunately, it is not possible to remap this action onto the spacebar on its own. The programmed action of space in command mode,
set_motion {"clip_to_line": true, "motion": "vi_move_by_characters", "motion_args": {"extend": true, "forward": true, "visual": false}}
just seems to be hard-programmed in. Sorry.

How to use sidebar with the keyboard in Sublime Text 2 and 3?

When using Sublime Text 2 we tend to open the side bar to navigate thru files/folders in our projects. For that we can use the hotkey ctrl+k ctrl+b (in windows).
However, once we're in the side bar, we can't use it with keyboard (arrows for instance). We have to stick using it with our own mouse...
Just a note: I installed SideBarEnhancements plugin, but I didn't find anything that could solve my problem.
Any solution you might know?
You can type Ctrl+0 (Ctrl+Zero) to focus on the side bar.
Then you'll be able to move selection among files with arrow keys and to open the selected file hitting Enter, without touching the mouse.
Another useful shortcut: ctrl + k Together with ctrl + b will show/hide the sidebar. Make sure you hit K and B in the right order
I didn't find any other complete answers, so I pulled together information from various answers and added a bit of my own.
Ctrl+K, Ctrl+B: toggle the sidebar
Ctrl+K+B: shorted form of the above (make sure you hit K and B in the right order)
Ctrl+0: switch focus to the sidebar (if open)
Up/Down: navigate file list
Right: expand a directory
Left: collapse a directory/navigate to parent directory
Enter: open a file
#Santiago Agüero The part you were missing was that the sidebar needs focus before the arrow keys will work (Ctrl+0).
As far as I can know, these shortcuts all work in Sublime 3, as well as Sublime 2.
One caveat: these assume you are using the default keybindings. But you can easily customize the keybindings by opening Preferences > Key Bindings - User and copying over lines from Preferences > Key Bindings - Default, changing the keys value as needed. E.g.,
{ "keys": ["ctrl+k", "ctrl+b"], "command": "toggle_side_bar" },
{ "keys": ["ctrl+0"], "command": "focus_side_bar" },
P.S. To get the fancy-looking keyboard glyphs, use the <kbd> HTML tag. E.g., <kbd>Key</kbd> will turn into Key. (Thanks to https://meta.stackexchange.com/questions/5527) :)
Summary
Ctrl + 0 will navigate to your sidebar. By default you can navigate the folders with your arrow keys. If you prefer 'Vim' type settings, you can avoid using the arrow keys by remapping your keys to the typical Vim settings (hjkl).
h will minimize/open a folder
j will navigate down (i.e. down arrow)
k will navigate up (i.e. up arrow)
l will open up a folder
Enter will open the file
Key mappings
To set this up, open Preferences > Key Bindings - User and add the following:
{ "keys": ["h"], "command": "move", "args": {"by": "characters", "forward": false}, "context":
[ {"key": "control", "operand": "sidebar_tree"} ] },
{ "keys": ["j"], "command": "move", "args": {"by": "lines", "forward": true}, "context":
[ {"key": "control", "operand": "sidebar_tree"} ] },
{ "keys": ["k"], "command": "move", "args": {"by": "lines", "forward": false}, "context":
[ {"key": "control", "operand": "sidebar_tree"} ] },
{ "keys": ["l"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[ {"key": "control", "operand": "sidebar_tree"} ] }
Ctrl+p is also really useful for opening files without using the mouse.
If you open a folder in Sublime all the files in that folder (and files in contained folders) will show up in the search you get with Ctrl+p.
Just hit Ctrl+p and start typing parts of the filename and you'll get a list of matches.
For sublime text 3 use Ctrl+K+B
Press and hold Ctrl then press and holdK and then press B
For Sublime Text 2 (and also Sublime Text 3) on Windows use Ctrl+0 to focus on the side bar, and use Ctrl+1 or Esc key to focus on the editor. And if it didn't work, use those 0 and 1 keys that exist in the numeric keys row under the function keys row rather than those 0 and 1 keys that exist in the numeric keypad of the keyboard. This image may demonstrate better: http://en.wikipedia.org/wiki/File:Qwerty.svg
In Sublime Text2, press keys in following format "Ctrl+k+b" and it will work on ubuntu.
It worked on my machine (v14.04 LTS)
I actually had the same issue, the fact that I had to trigger the reveal in side bar and then move focus to the sidebar, alongside with the fact that if the file's folder was already unfolded the focus would move to the sidebar's top, all this made me write a new plugin to reveal the file in sidebar and then move focus to there, making it a lot easier to navigate the sidebar with keyboard arrows, give it a try =)
https://github.com/miguelgraz/FocusFileOnSidebar
Another option is to use the FileBrowser package, which gives you many more actions and can be modified to your needs.
https://packagecontrol.io/packages/FileBrowser
Ctrl + 0 will focus on the side bar.
Ctrl + 1 will focus on the editor in the 1st window.
Ctrl + 2 will focus on the editor in the 2nd window etc.
Sandeep made a great post about improving the keyboard shortcut toggling side bar on/off.Go to Preference->Key Binding and enter:
[
{ "keys": ["ctrl+\\"], "command": "toggle_side_bar" },
]
save it and then press "ctrl+\" to toggle the sidebar.
In Linux new keybindings are saved in ~/.config/sublime-text-3/Packages/User/'Default (Linux).sublime-keymap'.
You have to add a folder to the Sublime Text window in order to navigate via the sidebar. Go to File -> Open Folder... and select the highest directory you want to be able to navigate.
enter this shortcode on Preference->Key Binding
[
{ "keys": ["ctrl+\\"], "command": "toggle_side_bar" },
]
now save it press
"ctrl+\\" for toggle the sidebar

How can I hide and unhide the project folder tree in sublime-text

I can no longer see the project folder navigation tree on the left side of my interface.
I suspect I have hit some shortcut by accident that made it go away.
What are the shortuts to make the project folder navigation tree hide and unhide in sublime text?
By default:
{ "keys": ["ctrl+k", "ctrl+b"], "command": "toggle_side_bar" },
You can reach this settings at main menu: Preferences -> Key Bindings - Default.
and you can override as you like, at main menu: Preferences -> Key Bindings - User.
By default if you are using mac os:
{ "keys": ["command+k", "command+b"], "command": "toggle_side_bar" }
In Command Panel (Ctrl+Shift+P) type (or find) View: Toggle Side Bar and hit Enter
I had something like that in my keymap.
{"keys": ["super+k", "super+b"], "command": "toggle_side_bar"},
In View -> Side Bar -> Show/Hide sidebar ⌘K, ⌘B.
Which means "Press and hold cmd then click buttons "b" and "k", then release cmd".
I couldn't get that... I thought that there were two ways to toggle project tree (cmd+B OR cmd+K) but it's basically one command.
View / Side Bar / Show Sidebar ⌘K, ⌘B
To Toggle (hide or show) the side bar
press ctrl+K,ctrl+B (ctrl+K,B)