Sublime Text 2 user keybindings not working - sublimetext2

I've followed several tuts and SO advice but Sublime Text User bindings are not working as follows:
[
{ "keys": ["ctrl+shift+u"], "command": "upperCase" }
]
I have removed the possible conflicting
{ "keys": ["ctrl+shift+u"], "command": "soft_redo" },
From default keybindings... Can anyone help me get custom keybindings to work? Also "command": "upperCase" is that just a command built into ST? Where can I find a comprehensive list of such commands?

To determine the name of the command to use in a keybinding, first open the console with Ctrl` (backtick) or by selecting View -> Show Console. Enter the following command:
sublime.log_commands(True)
and hit Enter. With the console still open, select the option you want from the menu (in this case Edit -> Convert Case -> Upper Case). The following will then appear in the console:
command: upper_case
You can now use this command in your key binding.
When you're done, enter
sublime.log_commands(False)
in the console to stop logging, then close the console by hitting Ctrl` or Esc.
If you want to find out what commands the different key bindings and menu options fire, and you don't want to use the method above, take a look at the default key bindings list (Preferences -> Key Bindings-Default) and/or the file Packages/Default/Main.sublime-menu where Packages is the folder opened when you select Preferences -> Browse Packages....

Related

Sublime Text - Pull in namespace automatically without typing?

I'm using Sublime Text 3 as text editor. I have seen some training videos where the instructor is pulling automatically the namespaces at the top lines of the .php file without typing. As far as I know this is a built-in feature in phpstorm, but I was wondering whehter this is available and for Sublime too?
I assume this can be done probably by a key shortcut or by installing a package? Anyone who knows how to do this?
If you use first use Package Control to install 'PHP Companion' (aka SublimePHPCompanion), you can add the keyboard shortcuts to do this.
1) Package Control: Install Package > PHP Companion
2) Menu: Sublime Text> Preferences > Key Bindings
3) Add the following lines (change f9/f10 if you want to use different keys)
{ "keys": ["f9"], "command": "expand_fqcn" },
{ "keys": ["f10"], "command": "find_use" }
Then you can use F9 to add the full path when typing a use command. If adding elsewhere in your code, F10 will add the full use statement at the top of the file for you.
There are other things you can add and more details at PHP Companion

Sublime text editor: Change plugin hotkey?

In Sublime Text 2 or 3 (I use both, and the answer is probably the same for both), how do you change the hotkey of an installed plugin/package? (on Windows or Linux / Ubuntu)
I already know how to change the key bindings of built-in Sublime commands (Preferences > Key Bindings). For instance, one binding I already have is:
{"keys": ["ctrl+super+b"], "command": "show_panel", "args": {"panel": "output.exec"}}
But in the case of a plugin, how do I know what string to use for "command"? Is there an easy way to find out what the "command" is for an arbitrary function in Sublime?
I would like a general answer that applies to any plugin one could install. Though as an example, today I'm trying to change the hotkey for a plugin called SimpleClone, which has assigned Ctrl+Shift+Right to Split Right. Ctrl+Shift+Right is a rather poor hotkey choice by the maker of the plugin since it already has a use in the operating system: when typing it selects the word to the right. Hence I want to change the assigned key binding.
If plugin has some shortcuts defined, they will be in the *.sublime-keymap files. So if you want to find some shortcut I guess you could grep through all the *.sublime-keymap files in Packages directories, but if you roughly know which plugin uses that shortcut you want to change that shouldn't be necessary :)
For example the Emmet plugin has keybindings defined in: Packages/Emmet/Default (Platform).sublime-keymap.
You can copy the keybinding definitions from these files to your user keybindings file (Packages/User/Default (platform).sublime-keymap) and modify them as you want.
You can open Packages list by pressing Cmd-Shift-P (on Windows should be Ctrl-Shift-P), choosing Package Control: list packages then select the package you neeed and press Enter. Sublime will open package directory where you can find all desired *.sublime-keymap files.
You can do the following:
Go to "Menu->Preferences->Browse packages..."
Find the directory of the interested package.
Find file with ".sublime-commands" extension.
Get command name from file.
Use "Menu->Preferences->Key bindings" for add key binding.
Ex (StringUtilities):
[
{ "keys": ["ctrl+b"], "command": "convert_to_base64" },
{ "keys": ["ctrl+shift+b"], "command": "convert_from_base64" },
{ "keys": ["ctrl+u"], "command": "url_encode" },
{ "keys": ["ctrl+shift+u"], "command": "url_decode" }
]

Sublime Text open a specific file with the command palette or key binding

How do I open a specific file with a custom command palette entry or with a key binding aka shortcut key?
There are some files I open a lot but are not associated with any specific project. It would be useful to be able to open them quickly using the command palette or with a key binding.
It took a few minutes of trial and error to work out how but here's how to do it.
To add an entry in the command palette to open a specific file, add a modified version of the following template to your user Default.sublime-commands file.
// Modify the caption "File Open: Whatever" to something
// appropriate and of course change the file path.
{ "caption": "File Open: Whatever", "command": "open_file",
"args": {"file": "/path/to/whatever"} },
To add a key binding to open a specific file, add a modified version of the following template to your user Default (OS).sublime-keymap file.
// Modify the key bindings to what you want and change the file path.
{ "keys": ["ctrl+t", "ctrl+w"], "command": "open_file",
"args": {"file": "/path/to/whatever"} },
Hope this helps.

Creating a "Repeat last macro" keybinding in sublime text vintage mode

At the moment, I am trying out sublime text. Most of it is fine, but there is one big feature that I can't figure out how to implement in sublime text. In vim, have have space bound to repeat the last macro that I performed. However, I can't find a good way to implement it in sublime text.
In an effort to learn more, I looked at the macro key bindings in the vintage package:
{ "keys": ["q"], "command": "vi_end_record_macro",
"context": [{"key": "setting.command_mode"}, {"key": "is_recording_macro"}]
},
{ "keys": ["#", "<character>"], "command": "vi_replay_macro",
"context": [{"key": "setting.command_mode"}]
},
And (what I think) is the relevant class in the actual plugin:
class ViReplayMacro(sublime_plugin.TextCommand):
def run(self, edit, character):
What I am unable to figure out is how to remember what the last command was, and failing that just have space call the vi macro recorded on 'q'. This means I need to bind vi_replay_macro(q) to space, but I don't understand how the key binding passes which character to replay to the command.
EDIT: I created a plugin that does it.
You would probably have to write your own plugin to run the last macro run. You can try using the command_history method, then search backwards till you find a vi_replay_macro or run_macro command. I'm just making a guess though based on what I know about ST, so there could be other ways to go about it.

Keymap Sublime Text 2 File Type?

I am working on setting up my own keymaps and was wondering if there is the option to set keys to switch the file type that is being worked on. So for example, if I have a regular plain text file and want it to be a css file, I would have a keymap that would change the document type to css. Possible? If so, please explain to me how you have done this.
Rob
The keybinding for this would be:
{
"keys": ["YOUR_SEQUENCE"],
"command": "set_file_type",
"args": {"syntax": "Packages/CSS/CSS.tmLanguage"}
}
How to discover command names:
Open the console
Type sublime.log_commands(True)
Go to an open tab
Open the command palette and type Set Syntax: CSS
The name of the command and it's required arguments should be logged to the console. From there you just put it in the right JSON syntax.
While the individual shortcut solution is great, it requires editing the config files and most importantly remembering all the shortcuts you create for each sytax.
In the case of switching file formats it might be more useful to quickly access the required format via the command palette:
Press CTRL+SHIFT+P to bring up the Command Palette
Type CSS to highlight Set Syntax: CSS command
Press ENTER
This is great because it provides quick access to all the formats available. Start typing set syntax... and all the available formats will be shown.