Sublime Text - Pull in namespace automatically without typing? - namespaces

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

Related

PhpStorm keymap for Sublime Text 3

I want to have PhpStorm keyboard shortcuts inside Sublime Text 3. Is it possible? How can I do it? I use Linux Mint if there is any difference.
I use these shortcuts the most:
reformat code
comment
PHPDoc comments
duplicate line/selected word/selected sentence ... (with one single shortcut Ctrl+D),
select word/line/childs (Ctrl+W),
I like the last one a lot -- you can select whatever is inside a tag or braces or other things with Ctrl+W and if you press it more than once the current parents whole childs and then current parent and then current parents parent and so on will be selected.
I want actually all of PhpStorm's shortcuts inside SublimeText 3.
As far as I know there is no possibility to export keys from phpstorm into sublime, but you can specify your keys in sublime with same values like in phpstorm, for example:
After that, you can export: settings.jar from phpstorm and save Sublime Text 3/Packages/User/Default (OSX).sublime-keymap from sublime somewhere on drive or cloud so you will have this keys forever. You can loosely import this keys in different versions of phpstorm and copy-paste keys from sublime-keymap into different versions of sublime.

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" }
]

Why doesn’t this hotkey configuration for Sublime Text work?

I have configured Ctrl+B to open a file in my browser, but when I press Ctrl+B when the editor is focused on some HTML page, it doesn’t work. Why not?
more details:
what makes me confused is that this ctrl+b works if it is combined to other command such as close, but why not openInBrowser command, so does st2 support this command, how to know whether it support this command or not?
Edit 1:
you may find openInBrowser command in this link http://www.sublimetext.com/docs/commands
Edit 2
#MattDMo what is the corresponding name of command then, i cannot find them in its official document http://www.sublimetext.com/docs/2/
The command you are looking for is open_in_browser, not openInBrowser (which is an old Sublime Text 1 command). So, your keymapping should work with that. However, if you weren't already aware, CtrlB is already mapped to the Build command, used for running build systems. It's not a very good idea to overwrite built-in commands, especially one as important as this one, so I'd suggest changing your keybinding to:
{ "keys": ["ctrl+alt+b"], "command": "open_in_browser" }
This isn't in use by any of the default Sublime commands, although some plugins may use it.

Sublime Text 2 user keybindings not working

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....

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.