Sublime Text 3- Main Menu Bar Customization - sublimetext3

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.

Related

Visual-Block mode not working in Vim with C-v on WSL#Windows 10

I use WSL Ubuntu and Vim inside the new Windows Terminal, but if I have to enter the visual-block mode with C-v, I can't since it acts as paste.
I am okay with rebinding it to something else but I don't happen to have found the command that I have to add to .vimrc, I think it has something to do with inoremap.
Any advice?
CTRL+v is bound to paste in Windows Terminal by default. As of now, the only thing that's working is to disable that behaviour in the settings.json. You can do that by pressing CTRL+, or just select Settings in this menu, then click on "Open JSON file" at the bottom left corner and comment out the line:
"keybindings": [
...
// { "command": "paste", "keys": "ctrl+v" }, <------ THIS LINE
After doing this, you can switch to visual block mode as usual and paste with CTRL+SHIFT+v.
I've found these issues on the project's GitHub about this problem:
https://github.com/microsoft/terminal/issues/5790
https://github.com/microsoft/terminal/issues/5641
You can just change the default "settings.json"
Orignal :
{
"command":
{
"action": "copy",
"singleLine": false
},
"keys": "ctrl+c"
},
{
"command": "paste",
"keys": "ctrl+v"
},
Modified :
{
"command":
{
"action": "copy",
"singleLine": false
},
"keys": "ctrl+shift+c"
},
{
"command": "paste",
"keys": "ctrl+shift+v"
},

SublimeText key binding for "Save Project as"?

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

How do I keybind SublimeREPL to run Haskell interpeter?

I've been searching for the right command name to keybind to run Haskell Interpeter in Sublime 3. I'm trying to add to the Sublime key bindings - user and the code should look something like this:
{ "keys": ["alt+keypad2"], "command": "run_existing_window_command", "args":
{
"id": "repl_haskell_run",
"file": "config/Python/Main.sublime-menu"
}
},
The following line is wrong, I made it up and I need to find the right command to put there:
"id": "repl_haskell_run",
"file": "config/Python/Main.sublime-menu"
I think the following does what you are looking for. I found the command by looking for a .sublime-menu file in the Haskell folder of the SublimeREPL repo: config/Haskell/Default.sublime-commands. (One such file had to exist for you to be able to do ctrl + shift + p -> SublimeREPL: Haskell.)
[
{ "keys": ["alt+keypad2"],
"command": "run_existing_window_command",
"args": { "id": "repl_haskell", "file": "config/Haskell/Main.sublime-menu" } },
]

How to set key-bindings in Sublime that change values of settings?

I'm looking to bind the "alt+f11" binding to toggle "draw_centered", which centers the text as in Distraction-free mode. I'm not sure how to get it to work though.
Heres my keybinds so far:
//if draw_centered == true, set to false
{ "keys": ["alt+f11"], "command": "set_setting", "args":
{
"setting": "draw_centered",
"value": "true",
},
"context":
[
{ "key": "setting.draw_centered", "operator": "equal", "operand": false}
]
},
//if draw_centered == false, set to true
{ "keys": ["alt+f11"], "command": "set_setting", "args":
{
"setting": "draw_centered",
"value": "false",
},
"context":
[
{ "key": "setting.draw_centered", "operator": "equal", "operand": true}
]
}
I couldn't find a command that automatically toggled "draw_centered", so I had to resort to building some sort of advanced command. I'm having a bit of trouble understanding the documentation on keybindings, but I tried to follow the "Contexts" example. Could anyone point to what I'm doing wrong?
Thanks sergioFC for the tip about toggle_setting! I got it to work with this code:
{ "keys": ["alt+f11"], "command": "toggle_setting", "args":
{
"setting": "draw_centered",
}
}
EDIT: I discovered a bug with this. After using the key-combination "alt-f11" now, the distraction-free mode isn't behaving like it should. It now follows the draw_centered state that I am in when I switch from normal to distraction-free mode.
For example: if I have a file opened and click 'alt-f11' so I am left-aligned (i.e. draw_centered = false) , the window will remain left-aligned when I enter distraction-free mode. Any ideas as to why this is and how to fix it?
A little late, but it took me a while to find out how to do something similar and this was the most closest question to what I was trying to achieve.
toggle_setting only works in the current view(file you are working on), it also won't work in other options like show_encoding, because these aren't too related to the view specifically rather than being more part of the panel spectrum.
After digging a couple of hours I found an old plugin called Cycle Settings, this one was for Sublime 2, but after a little tweaking it worked as expected.
(I remember that there was an option to create packages directly in sublime, but don't remember where..)
Go to Preferences/Browse Packages... and create a new file there
"Cycle Settings/cycle_setting.py" and the following code there:
"""
Cycle Setting plugin for Sublime Text 3.
Copyright 2011 Jesse McCarthy <http://jessemccarthy.net/>
Adds a command that can be called from a key binding to toggle or
cycle through values for a setting.
The Software may be used under the MIT (aka X11) license or Simplified
BSD (aka FreeBSD) license. See LICENSE
"""
import sublime, sublime_plugin
class CycleSettingCommand(sublime_plugin.TextCommand):
def run(self, edit, setting, options):
"""Cycle $setting to next of $options"""
index = len(options)
if not index :
return
settings = sublime.load_settings('Preferences.sublime-settings')
value = settings.get(setting)
if value in options :
index = options.index(value)
index += 1
if index >= len(options) :
index = 0
value = options[index]
settings.set(setting, value)
sublime.save_settings('Preferences.sublime-settings')
self.view.set_status(
'cycle_setting',
"Setting '{setting}' cycled to value '{value}'".format(**locals())
)
Now, lets use our new command for bindings
Go to Preferences/Key Bindings
[
{
"keys": ["f5"],
"command": "cycle_setting",
"args": {
"setting": "draw_centered",
"options": [true, false]
}
},
{
"keys": ["shift+f5"],
"command": "cycle_setting",
"args": {
"setting": "default_line_ending",
"options": ["system", "windows", "unix"]
}
}
]
What our command is doing is cycling through the options array and saving the current one in the cycle to User/Preferences.sublime-settings.
I hope this helps someone else, I actually spend a while trying to find how to achieve this with many commands for external plugins and at this rate I was soon going to run out of key combinations, regards!

Sublime Text 2 config - Let space save the file

Sublime Text 2 already supports normal Vim bindings. However, I'd like to have it support saving the current file when pressing space in command mode.
This key binding has become one of my number one features I love about vim.
However, when trying to write this key binding, Sublime Text 2 seems to ignore it:
{ "keys": ["space"], "command": "save",
"context":
[
{ "key": "setting.command_mode", "operand": true }
]
}
Sublime Text 2 seems to not recognize "space".
It much rather has to be like this:
{ "keys": [" "], "command": "save",
"context":
[
{ "key": "setting.command_mode" }
]
}

Resources