How can I set the shortcut key for right key -> show unsaved changes in Sublime Text 3?
I have tried
{ "keys": ["alt+f10"], "command": "show_unsaved_change" },
but it does not work.
You have the wrong command name, the correct command name is diff_changes:
{ "keys": ["ctrl+alt+d"], "command": "diff_changes" }
Related
I found the documentation here and here (under moveActiveEditor) for moving tabs, but I have trouble creating a key binding for it.
I created the following (for a Mac, so it uses cmd):
[
{
"key": "alt+cmd+right",
"command": "moveActiveEditor",
"args": {
"to": "position",
"value": i + 1
}
}
]
But when I hit that key command, the tab moves to the first tab position instead of moving one tab position to the right. So clearly, the value of i is 0, meaning it isn't returning the correct value of the current tab.
How can I get this to work?
You need to replace position with right and remove the value attribute:
[
{
"key": "alt+cmd+right",
"command": "moveActiveEditor",
"args": {
"to": "right"
}
}
]
I'm trying to make a key binding to open up my favorite git application with current Sublime Text 3 $project_path folder, but somehow Sublime Text 3 doesn't convert the variables into the actual path.
Below you can find my current keyboard bindings file.
[
{
"keys": ["super+ctrl+alt+g"],
"command": "exec",
"args":
{
"shell_cmd": "open -a Gitbox $project_path"
}
}
]
$project_path doesn't convert into the actual project path... What am I doing wrong? Should I use a "Build System" instead? I looked into build systems but the problem there is that you would have to select a scope of files (for example *.rb) and I want this keyboard shortcut to be valid for all my projects/files.
In textmate2 the same shortcut was easily achieved by creating a new "Command" in the Bundle Editor and assigning a shortcut to it. The command then would be:
#!/usr/bin/ruby
exec "open -a Gitbox '#{ENV['TM_PROJECT_DIRECTORY']}'"
So I'm trying to achieve this same thing in Sublime Text 3 but something is going wrong.
Thanks!
Edit:
In the meantime I've built a generic plugin which gives you the ability to open any external application with an key stroke or via the command palette.
The plugin can be found here: ExternalTools
You can easily install it via the command palette cmd+shift+p
In your case you can go to Preferences / Key Bindings and add the following:
{
"keys": ["super+ctrl+alt+g"],
"command": "external_tools_run",
"args": { "cmd": ["open", "-a", "Gitbox", "$project_path"] }
}
I still down't own a mac so there is a chance that it is not working properly. In this case I would be pleased if you can give me a feedback (see Issues).
Original Answer:
I have spend a few hours searching on the same problem. After all I decided to create a small plugin with my own place holders.
import sublime, sublime_plugin
class RunAppCommand(sublime_plugin.WindowCommand):
def run(self, app_args):
app_args = self.fill_placeholder(app_args)
self.window.run_command("exec", {"cmd": app_args } )
def fill_placeholder(self, args):
res = []
proj_folder = self.get_project_folder()
for arg in args:
arg = arg.replace("$PROJECT_FOLDER", proj_folder)
res.append(arg)
return res
def get_project_folder(self,default=None):
proj_folder = ""
if self.window.project_file_name():
proj = self.window.project_data()
proj_folder_obj = self.get_first(proj["folders"])
if proj_folder_obj:
proj_folder = proj_folder_obj["path"]
elif self.window.folders():
proj_folder = self.get_first(self.window.folders())
if not proj_folder:
sublime.status_message("No project folder located")
return default
return proj_folder
def get_first(self, iterable, default=None):
if iterable:
for item in iterable:
return item
return default
After you have saved the code above to Packages/User/RunApp.py you can make your command work just by adding the following to your Default.sublime-keymap:
{ "keys": ["super+ctrl+alt+g"], "command": "run_app", "args": { "app_args": ["open", "-a", "Gitbox", "$PROJECT_FOLDER"]}}
This may be not the best solution but it works for me.
Also spent some hours searching here - thanks to fboers example i could finally
create a plugin myself.
So here's my solution: exec2 - expands all the sublime-variables as it should be and then forwards it to exec.
Save this as Packages/Exec2/Exec2.py.
import sublime
import sublime_plugin
class Exec2Command(sublime_plugin.WindowCommand):
def run(self, cmd):
new_cmd = [sublime.expand_variables (value, self.window.extract_variables()) for value in cmd]
self.window.run_command("exec", {"cmd": new_cmd } )
Example for the keybinding:
{ "keys": ["ctrl+F7"], "command": "exec2", "args" : { "cmd": ["V:/v4_tools/v4Doccer.exe", "--mdi", "${file}"]} },
I would like to customize shortcut, but apply them only to a specific extension.
For example,
"jump to matching bracket" -> works in JS files -> customly bound to ctrl+m,
"go to matching tag pair" (emmet) -> works in HTML files -> I would like to ctrl+m also here, but doesn't work (ST3 understand "jump to matching bracket" which doesn't apply here).
I was wondering if specializing a shortcut to a specific extension would do the trick?
Apparently you can try something like this:
[
{ "keys": ["ctrl+x", "ctrl+i"],
"command": "insert_snippet",
"args": {"name": "Packages/User/mysnippet.sublime-snippet"},
"context": [ {"key": "selector", "operator": "equal", "operand": "text.tex.latex"} ]
}
]
Where you'ld replace the first 3 lines by what you want, and text.tex.latex by the scope you want (source.js and text.html.basic in your case).
When I type the start of a tag, Sublime Text will auto-complete the end of the tag and position the cursor inside the tag.
<code>|</code>
I use | to represent the cursor. So when I finished the contents inside the tag, I want to move the cursor to the end of the tag like this:
<code>blabla</code>|
To do this, now I have to press Right button to move the cursor character by character, which is not efficient. Is there any shortcut to move the cursor to the end of the tag directly?
You could also create a macro. This may be valuable if your tags cover multiple lines. Save the following as something like move_to_end_tag.sublime-macro in Packages/User.
[
{
"args":
{
"to": "tag"
},
"command": "expand_selection"
},
{
"args":
{
"by": "characters",
"forward": true
},
"command": "move"
}
]
You can then create a keybinding for the action.
{
"keys": ["ctrl+shift+alt+right"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/move_to_end_tag.sublime-macro"}
}
Of course, you can change the keys to whatever you like.
I'm working in Sublime Text 3 rather than 2, but the End button (for me, between the delete and page down) does the trick for me.
I found that annoying as well. Personally, taking the End key binding and applying it to Shift+Space works well enough for my purposes.
If that's easier for you, you can add this line to your user key bindings:
{ "keys": ["shift+space"], "command": "move_to", "args": {"to": "eol", "extend": false} }
Using a macro as skuroda suggested is a good option as well since you end up with more control of the cursor placement.
For curly braces and parentheses you can use Control + M.
Not sure about angle brackets in markup though.
I want to create an Eclipse style shortcut Ctrl+MouseClick to open the function/method. Sublime Text 3 has already this function called goto_definition but it is bound to F12.
But I'm not sure how to create this binding. I looked here for documentation but it was too complex. Can you one help me out with this simple key binding?
Edit: Following this article I was told to do this: http://webtempest.com/better-definition-navigation-in-sublime-text-3/
[
{
"button": "button1",
"count": 1,
"modifiers": ["super", "shift"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
This doesn't seem to work, ctrl+shift+click executes nothing.
For anyone else who wants to set Eclipse style goto definition, you need to create .sublime-mousemap file in Sublime User folder.
Windows - create Default (Windows).sublime-mousemap in %appdata%\Sublime Text 3\Packages\User
Linux - create Default (Linux).sublime-mousemap in ~/.config/sublime-text-3/Packages/User
Mac - create Default (OSX).sublime-mousemap in ~/Library/Application Support/Sublime Text 3/Packages/User
Now open that file and put the following configuration inside
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
You can change modifiers key as you like.
Since Ctrl-button1 on Windows and Linux is used for multiple selections, adding a second modifier key like Alt might be a good idea if you want to use both features:
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl", "alt"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
Alternatively, you could use the right mouse button (button2) with Ctrl alone, and not interfere with any built-in functions.
To set go to definition to alt + d. From the Menu Preferences > Key Bindings-User. And then add the following JSON.
[
{ "keys": ["alt+d"], "command": "goto_definition" }
]
If you want to see how to do a proper definition go into Sublime Text->Preferences->Key Bindings - Default and search for the command you want to override.
{ "keys": ["f12"], "command": "goto_definition" },
{ "keys": ["super+alt+down"], "command": "goto_definition" }
Those are two that show in my Default.
On Mac I copied the second to override.
in Sublime Text -> Preferences -> Key Bindings - User I added this
/* Beginning of File */
[
{
"keys": ["super+shift+i"], "command": "goto_definition"
}
]
/* End of File */
This binds it to the Command + Shift + 1 combination on mac.
On a mac you have to set keybinding yourself. Simply go to
Sublime --> Preference --> Key Binding - User
and input the following:
{ "keys": ["shift+command+m"], "command": "goto_definition" }
This will enable keybinding of Shift + Command + M to enable goto definition. You can set the keybinding to anything you would like of course.
ctrl != super on windows and linux machines.
If the F12 version of "Goto Definition" produces results of several files, the "ctrl + shift + click" version might not work well. I found that bug when viewing golang project with GoSublime package.
I'm using Sublime portable version (for Windows) and this (placing the mousemap in SublimeText\Packages\User folder) did not work for me.
I had to place the mousemap file in SublimeText\Data\Packages\User folder to get it to work where SublimeText is the installation directory for my portable version. Data\Packages\User is where I found the keymap file as well.
One should not just configure the goto_definition shortcut -- you would also need a shortcut to go back(and forth) after you jump to the definition.
Hence, consider configuring all three shortcuts: goto_definition, jump_back, and jump_forward as follows in your Key Bindings config file :
// go to the definition
{ "keys": ["ctrl+i"], "command": "goto_definition" },
// go back to the previous location
{ "keys": ["ctrl+h"], "command": "jump_back" },
// go to the next location
{ "keys": ["ctrl+l"], "command": "jump_forward" },
I find these three commands especially useful while trying to read code quickly.