SublimeText is a customizable Text Editor. With default settings there is currently no key map bind to "Project/Save Project as" (v3.2.1).
How can I provide a key map for this command?
If you use View Package File from the command palette and open Default/Main.sublime-menu to view the definition of the main menu, you can search for the menu item caption and locate the command you're after:
...
{ "caption": "-" },
{ "command": "save_project_and_workspace_as", "caption": "Save Project As…", "mnemonic": "A" },
{ "command": "close_workspace", "caption": "Close Project", "mnemonic": "C" },
{ "command": "open_file", "args": {"file": "${project}"}, "caption": "Edit Project" },
{ "caption": "-" },
{ "command": "new_window_for_project", "caption": "New Workspace for Project" },
{ "command": "save_workspace_as", "caption": "Save Workspace As…", "mnemonic": "A" },
{ "caption": "-" },
{ "command": "prompt_add_folder", "caption": "Add Folder to Project…", "mnemonic": "d" },
{ "command": "close_folder_list", "caption": "Remove all Folders from Project", "mnemonic": "m" },
{ "command": "refresh_folder_list", "caption": "Refresh Folders", "mnemonic": "e" },
...
Armed with the command save_project_and_workspace_as, you can use Preferences > Key Bindings and bind it to any key you want; for example:
{
"keys": ["ctrl+shift+p"],
"command": "save_project_and_workspace_as",
}
Related
I just installed Sublime Text 3 on my Windows system and like how it works and all the plugins that come with it, I added some customization to my main context menu, so that I can call the commands directly.
I added a caption with a whole bunch of empty spaces in it to look like it is on the second row, but when you hover it shows highlighting which looks clunky and shows on just one line when you maximize the window.
Is there a way to customize it where the added items on the menubar are stored on a separate row from the File,Edit,Selection,Find... menus without having to add a caption? The overall goal is to make it similar to Notepad++ toolbar.
Notepad ++ Toolbar:
Menu Code:
[
{
"id": "help"
},
{
"id": "folders", "caption":
" "
},
{
"id": "folders", "caption":
"Shortcuts:"
},
{
"command": "prompt_open_folder",
"caption": "📁 Open Folder"},
{
"command": "new_file",
"caption": "🗋 New File"},
{
"command": "save",
"caption": "💾 Save"},
{
"command": "show_panel",
"args": {
"panel": "find", "reverse": false
},
"caption": "🔎 Find"
},
{
"command": "show_panel",
"args": {
"panel": "replace", "reverse": false
},
"caption": "🔍 Replace"
},
{
"command": "build",
"caption": "▶ Build"},
{
"command": "expand_selection",
"args": {
"to": "scope"
},
"caption": "♒ Expand"
},
{
"command": "fold_by_level",
"args": {
"level": 1},
"caption": "⮝ Fold"
},
{
"command": "unfold_all",
"caption": "⮟ Un-Fold"
},
{
"command": "open_terminal",
"caption": "🗔 Terminal"
}
]
Desired result:
Menus are displayed in Sublime by native OS methods (or in the case of Linux, via GTK3). As far as I'm aware there is no direct way to break the main menu into lines like you want other than by using the mechanism you're already using.
That said since the menus are displayed natively, it's theoretically possible that if there is a special character you can add to a menu caption for your OS that would make it break the menu, that would work.
On Linux for example your menu from above doesn't wrap and just makes the window large enough to fit the menu without a wrap. Similarly adding \r or \n to get a line break breaks the caption, but within the layout of it's own item and not in the menu as a whole.
Generally the UI of Sublime is intended to be as unobtrusive as possible to make as much room as possible for text, which is why the find and replace actions are small panels and not floating windows and why the toolbar that used to exist was removed in 2009.
I have update my sublime3 to newest version, then I can't use hotkey to run my py files. Here is my hot key configuration:
[
{
"caption": "Tmpl: Create python",
"command": "sublime_tmpl",
"keys": ["ctrl+alt+p"], "args": {"type": "python"}
},
{
"keys":["f1"],
"caption": "SublimeREPL: Python",
"command": "run_existing_window_command", "args":
{
"id": "repl_python",
"file": "config/Python/Main.sublime-menu"
}
},
{
"keys":["f2"],
"caption": "SublimeREPL: Python - RUN current file",
"command": "run_existing_window_command", "args":
{
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
},
]
When I press F2 or F1, there is nothing happened.
It appears that Sublime Text 3 build 3200 has broken the run_existing_window_command command. As alluded to in this answer the solution is to instead invoke the command that the SublimeREPL menu item is using.
If you navigate to your Sublime Text 3 packages directory (AppData/Roaming/Sublime Text 3/ by default on Windows), you can see the packages you have installed. From this directory, if you open SublimeREPL/config/Python/Main.sublime-menu, you'll see a big ole json file that looks something like this:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "R",
"id": "SublimeREPL",
"children":
[
{"caption": "Python",
"id": "Python",
"children":[
{"command": "repl_open",
"caption": "Python",
"id": "repl_python",
"mnemonic": "P",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
<---snip--->
]}
]
}]
}
]
Notice that the innermost children key is a list of dictionaries with commands and args. We're going to copy those into the sublime-keymap file and replace the command and args that are already there. For example, your shortcut to open a python REPL would now look like:
"keys": ["f1"],
"command": "repl_open",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
Hitting F1 should now work like it used to.
I'm using Lubuntu, have changed just one shortcut on sublime user keymap, but nothing that i change there takes any effect.
on default keymap, i have this
{ "keys": ["ctrl+pageup"], "command": "next_view" },
{ "keys": ["ctrl+pagedown"], "command": "prev_view" },
on userkeyma, i replaced it with this:
{ "keys": ["alt+pageup"], "command": "next_view" },
{ "keys": ["alt+pagedown"], "command": "prev_view" },
but it takes no effect whatsoever
this is sublime text 3 build 3083
I am using the keymap to execute the current line in sublime repl by hitting ctrl+enter. The cursor remains on the same line. What do I need to add to the keymap so the cursor would jump to the next line (as what happens in RStudio)?
[
{ "keys": ["ctrl+enter"], "command": "repl_transfer_current", "args": {"scope": "lines"}}
]
I found a way to do it using a python script plugin. Apparently, Sublime by default does not have the option of running multiple commands under a single keymap.
I used the method from here: https://forum.sublimetext.com/t/run-multiple-commands-command/6848
the steps are the following:
Sublime - Tools - Developer - New Plugin
copy code from run_multiple_commands.py found here: https://gist.github.com/bgmort/7ae52ea4270f1c404321c20d1b97733c#file-run_multiple_commands-py
and save the file under the same name as on github: run_multiple_commands.py
Sublime - Preferences - Key Bindings User
code:
{
"keys": ["ctrl+enter"],
"command": "run_multiple_commands",
"args": {
"commands": [
{ "command": "repl_transfer_current", "args": {"scope": "lines"} },
{ "command": "move", "args": {"by": "lines", "forward": true} }
]
}
}
or additionally add [ ] if the file is empty:
[{
"keys": ["ctrl+enter"],
"command": "run_multiple_commands",
"args": {
"commands": [
{ "command": "repl_transfer_current", "args": {"scope": "lines"} },
{ "command": "move", "args": {"by": "lines", "forward": true} }
]
}
}]
I've been trying to create a shortcut to the snippet palette in Sublime Text 3 but can't seem to get it to work. I don't get an error, I just get nothing. I am on a Mac and have the following in Preferences: Key Bindings - User
{
"keys": [ "ctrl+y" ],
"command": "show_overlay",
"args": {
"overlay": "command_palette",
"text": "Snippet:"
}
}
Did you put your code into this [] ?
It works for me:
[
{
"keys": ["ctrl+y"],
"command": "show_overlay",
"args": {
"overlay": "command_palette",
"text": "Snippet: "
}
}
]