问题
I can do this by clicking View -> Ruler -> 80
but it'd be a lot more convient to do it from the command palette or a hotkey (apart from alt, right, right, right, right, down, down, down, down, down, down, down, down, down, down, down, down, down, down, down, down, down, down, right, down, down, down, enter
).
Edit: Though I found a way to make a file to add command palette options, I do not know how to make it work for arbitrary numbers, ideally typing set ruler 33
would set the ruler to 33 and set ruler 44 66
would make a ruler at 44 and 66. I only know how to do it by making an explicit command for each value rather than a dynamic one for all of them.
回答1:
Once you have the menu bar focused, you can generally hit the first letter of a menu to open it (V for View
in this case), then the first letter of any submenus or options you wish to open or select, respectively. In previous versions of Windows (I haven't used Win10 yet) there was an option, usually set by default, to underline the "hotkey" of the menu item, which is especially useful if you have two menu items that begin with the same letter. If nothing is underlined, I would assume you can just start spelling out the menu item, so if you have View
and Verify
on the same submenu, you'd just type vi
for the first and ve
for the second one.
So, for your particular setup, just hit Alt to focus the menu bar, then V, R, 8 for View -> Ruler -> 80
, respectively.
As a freebie, I'll give you not one but two keyboard shortcuts as well:
{
"keys": ["ctrl+shift+8"],
"command": "set_setting",
"args":
{
"setting": "rulers",
"value": [80]
}
},
{
"keys": ["ctrl+shift+0"],
"command": "set_setting",
"args":
{
"setting": "rulers",
"value": []
}
}
Add these to your user keymap, and CtrlShift8 will set the rulers to 80, while CtrlShift0 will set them back to none. Remember that this is for the current view only, not all open files, and any newly-opened files or views will default back to the value in either your project, user settings, or default settings (in that order).
回答2:
It turns out making a file to add command line palette items is actually pretty easy! Make a file called ruler.sublime-commands
and place it in the Installed Packages folder (differs by OS, on windows it is C:\Users\<you>\AppData\Roaming\Sublime Text 3\Installed Packages
).
With the below content you can open the palette and type ruler 80
or unset ruler
.
[
{
"caption": "View: Unset Ruler",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": []
}
},
{
"caption": "View: Set Ruler: 70",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [70]
}
},
{
"caption": "View: Set Ruler: 72",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [72]
}
},
{
"caption": "View: Set Ruler: 78",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [78]
}
},
{
"caption": "View: Set Ruler: 80",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [80]
}
},
{
"caption": "View: Set Ruler: 100",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [100]
}
},
{
"caption": "View: Set Ruler: 120",
"command": "set_setting",
"args": {
"setting": "rulers",
"value": [120]
}
}
]
来源:https://stackoverflow.com/questions/37006406/how-can-i-set-the-ruler-in-sublime-from-the-command-palette-hotkey