Sublime Text open open relative to project directoy - sublimetext2

I have a command mapped to ahotkey in sublime to open the user directory...
{ "keys": ["ctrl+alt+u"], "command": "open_dir", "args": {"dir": "$packages/User/"} },
How can I have a similar command that opens a directory two levels up from the project directory?

The path variable $project_path expands out to the location of the current sublime-project file (which is specific to the current window) in the same way that $packages expands to the location of the Packages folder.
So, the following will open the directory two levels above the location of the current sublime-project file:
{
"keys": ["ctrl+alt+u"],
"command": "open_dir",
"args": {"dir": "$project_path/../../"}
},
Sometimes people store their sublime-project files in locations other than the locations where their project files are actually stored (e.g. to centralize them all in one location or to remove clutter).
In that case, if you want the binding to open two levels above where the contents of the project are, you can use the $folder variable, which expands out to the location of the first folder that's open in the project (or window).
{
"keys": ["ctrl+alt+u"],
"command": "open_dir",
"args": {"dir": "$folder/../../"}
},

Related

Easy check what keybindings are used in Sublime Text editor? [duplicate]

My default key-bindings for pasting are
{ "keys": ["ctrl+v"], "command": "paste" },
{ "keys": ["ctrl+shift+v"], "command": "paste_and_indent" },
I overrode them in my user key-bindings with
{ "keys": ["alt+k"], "command": "paste" },
{ "keys": ["ctrl+k"], "command": "paste_and_indent" },
I use Dvorak keyboard, which means your V is my K. Also, I want paste_and_indent to be the default.
But Ctrl+k executes paste, not paste_and_indent. I determined this by turning on command logging in the console, with
sublime.log_commands(True)
However, if I make the paste_and_indent command to something else, like Ctrl+Alt+k or Alt+k, it correctly calls paste_and_indent.
I looked through the key-bindings for all of my installed packages, and don't see any other command using Ctrl+k. I also disabled most of my packages except syntaxes. I even accidentally disabled Package Control, but still, Ctrl+k only executes paste.
How can I determine and fix this conflict, so Ctrl+k executes paste_and_indent?
Check out the FindKeyConflicts plugin. There are several options for looking at all key bindings, or just conflicting ones, in a variety of contexts. All the options are available via the Command Palette.

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.

"unable to open" a sublime text macro file

When I run my macro in sublime text, I get "unable to open:'file path'". The sintax in keymap file is OK, I'm able to save it. This is the key map :
{ "keys": ["ctrl+="], "command": "run_macro_file", "args": {"file": "C:\\Users\\Bane\\AppData\\Roaming\\Sublime Text 3\\Packages\\User\\test.sublime-macro"} },
I'm using win7/64bit.
Your path to the macro file needs to start at the Packages directory, and use Unix-style path delimiters (/). So, your keymap should look like this:
{ "keys": ["ctrl+="], "command": "run_macro_file", "args": {"file": "Packages/User/test.sublime-macro"} },
The paths are designed like this so the Packages directory can be portable, and the same command will work on all three supported operating systems.

Sublime Text 3 usage keymap user

How to embed current file path in a custom user keymap? I'm referring to this documentation:
http://sublimetext.info/docs/en/reference/build_systems.html
Which has been deprecated but I do not see equivalent documentation for $file_path variable which I need to use in my keymap in the latest documentation. I'm not having any luck. My keymap looks like this (trying to launch Google Chrome with flag to package my application):
{
"keys": [
"shift+ctrl+g"
],
"command": "exec",
"args": {
"cmd": [
"c:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
"--pack-extension=${file_path}"
]
}
}
The official documentation is here: https://www.sublimetext.com/docs/3/build_systems.html
You may toggle the version switch in the bottom of the sidebar. The $file_path variable still exists though, so it probably should work. You may try removing the wrapping braces { and }