I have a mouse with 5 buttons, how can I configure these buttons to do specific tasks in Sublime Text 3. Like when button4 does Build and button5 does Build With...
In case of Sublime Text, the mouse actions are configured by what are known as mousemap files (that have an extension .sublime-mousemap). You can have generally 2 variants of these files :-
Default.sublime-mousemap: This will define mouse actions for any platform.
Default ($platform).sublime-mousemap: This will define mouse actions for a specific platform, where $platform is any one of Windows, Linux or OSX depending on your operating system.
You can view the default shipped mousemap files by using View Package File from the command palette and searching for mousemap.
In order to define your own mouse actions (or override any existing actions), you have to create a file by the name of Default.sublime-mousemap in the User directory (to get to this directory, select Preferences -> Browse Packages ... from the main menu) for platform independent override (or Default ($platform).sublime-mousemap for platform dependent overrides depending on your OS).
Once that's done, here is some basic knowledge about mousemap files (Note that there is no official or community documentation about mousemap files so everything is based on experimentation and what the dev's have said about such files).
Here are the meaning of some keys in mousemap files :-
button: This defines the name of the button. For example, button1 refers to the left mouse button & button2 defines the right mouse button. Similarly, you can have button3, button4. button5 etc. I am not sure how many such button names actually exist. Also for the scroll wheel, you have scroll_up for upward scroll movement & scroll_down for the opposite behavior.
modifiers: This is a list of modifier keys like ctrl, alt etc. For example, ["alt"], ["ctrl", "alt"]. When you define a modifier list, all the modifier keys listed should be pressed simultaneously and then pressing/releasing the corresponding button triggers some action.
command: This defines the command to be executed when the corresponding button is released after being pressed. If this command takes any arguments, you can have an args key for it.
press_command: This defines the command to be executed when the corresponding button is pressed. If this command takes any arguments, you can have a press_args key for it.
count: The number of times you have to press the corresponding button to trigger the action (by action, I mean execute the corresponding command/press_command)
NOTE:
You can define both command and press_command if you wanted to.
Let's look at some examples :-
File name :- User/Default.sublime-mousemap
[
{
"button": "button2",
"modifiers": [],
"press_command": "echo",
"press_args": {
"message": "I am pressed"
},
"command": "echo",
"args": {
"message": "I am released"
},
}
]
Here, the right button (button2) is bound to the built in echo command. If you now right click, the default behavior would have been actually the opening of the context menu, but now we have overriden that behavior and now you can see the corresponding messages {'message': 'I am pressed'} or {'message': 'I am released'} in the console based on whether you have pressed or released after pressing.
For your case, you can have something like the following :-
[
{
"button": "button1", // replace button1 with button4/5 because I don't have that many mouse buttons.
"modifiers": ["alt", "ctrl", "shift"],
"press_command": "undo",
}
]
Now, when you now press button1 (while holding down alt, ctrl, shift simultaneously), the undo command should be executed. You can set modifiers to an empty list if you don't want that.
As for build, if you mean executing the most recent build system, replace undo, with build.
As a parting bonus tip, if you want to disable any button actions, just use the command noop.
Example :-
[
{
"button": "button1",
"modifiers": [],
"press_command": "noop",
}
]
This will disable button1 and now you can't drag select anymore ;-) So be careful.
Hopefully, this helps a bit.
Related
I have a web page, when I click one button(by both using mouse click or using keyboard with tab and press), it will show some items, normally, it works perfect.
However, if I
1> open windows magnifier with 200%,
AND
2> use keyboard with tab and press
to trigger the button,
the items still shows correctly,
but the whole page moves back and forth in horizon automatically until I move mmouse or press any key.
++++++
I got the root cause:
As I input the follow code
document.addEventListener('focus',
function()
{ console.log('focused: ', document.activeElement)
},
true);
in console to monitor the focused element,
it shows the focus are switch between two elements,
however, I try to set the two element with tabindex = 0 or -1,
and all the 4 combinations,
but it doesn't work.
Are you using "docked", "full screen", or "lens" view for the magnifier?
I'm guessing "full screen" because in that mode, as you tab through a page, the magnifier will try to keep the keyboard focus within view. You might have an issue where your focus is moving between two elements that both can't be displayed in the magnifier at the same time. Usually it will just move the magnifier to the element that has focus.
I'd suggest trying "Docked" and "Lens" view first to see if you still have an issue.
I am using the keyboard and then I get to the point I want to open the menu little menu, so I had to open it using right-click on the mouse since I couldn't find the shortcut.
What is the keyboard shortcut to do "right-click" and open the little menu that pop-up?
What you are calling the "little menu" is called a "context menu" (see Wikipedia).
Sublime Text does set a key binding for this but which one depends on your operating system.
// OSX:
{ "keys": ["alt+f2"], "command": "context_menu" },
// Linux and Windows - context_menu is a keyboard key:
{ "keys": ["context_menu"], "command": "context_menu" },
For Linux and Windows the expectation is that the keyboard has a special key assigned to opening a context menu, usually this is called the menu key and has a menu or document icon printed on it, see this Google images search for example photos.
For the purposes of key bindings Sublime Text refers to the menu key as context_menu, this may be slightly confusing because Sublime Text also uses context_menu as the command name to open a context menu.
You can of course change the Sublime Text context menu key binding to whatever you want in the usual way. For example to ctrl+shift+y, e.g.
{ "keys": ["ctrl+shift+y"], "command": "context_menu" },
Your screen capture shows a context menu being opened on a file name in the Sublime Text side bar. I do not think this can be done by just using keys, unfortunately I think it requires the mouse. The "ctrl+0" keys force the focus to the side bar (the same keys for all OSes) but once that is done pressing the context menu's keys does not open the context menu in the way that you have shown. This is certainly true on Linux (which I use) and probably also true on Windows and OSX. Perhaps users of those OSes could add a comment to confirm whether that is the case or not.
I use sublime text for python. I am using default setup so after I run (F7) the script, the result/output of the python script will appear in the bottom viewing panel.
But the problem is, during the script execution, I often need to work on the same script and sometime needs to search a word in the main programming panel, and as soon as I go Ctrl+F to search, the bottom viewing panel disappear. How can I make it reappear so I can see my results after the script has finished running?
Sublime only allows a single panel to be open at a time, which is why when you open the find panel, the build output goes away.
You can get the build results to re-appear in the following ways:
Select Tools > Build Results > Show Build Results from the main menu
Select Build: Show Results from the command palette
Click on the panel switcher and select Build Results from the pop up menu; the panel switcher is the icon all the way to the left in the status bar at the bottom of the window:
You can also create a key binding like the following (swap the key for something more appropriate for you) to open the panel with a key instead as well:
{
"keys": ["ctrl+alt+shift+b"],
"command": "show_panel",
"args": {
"panel": "output.exec",
},
},
Is there a dynamic way to enable and disable invisible white space display apart from persistent setting, via:
"draw_white_space": "all",
The only way to control the state of the display for white space is via changing the setting that you reference in your question, draw_white_space:
// Set to "none" to turn off drawing white space, "selection" to draw only the
// white space within the selection, and "all" to draw all white space
"draw_white_space": "selection",
For many such settings that are a Boolean value, you can bind a key to the toggle_setting command, telling it what setting that you want to toggle between. However, for the case of the draw_white_space option, it takes a string argument of either "all", "selection" or "none" and so the standard toggle command won't work.
The following is a simple plugin that implements a toggle_white_space command which performs this operation for you. To use it, select Tools > Developer > New Plugin... from the menu, replace the stub code you see with the plugin code here, and then save it as a .py file in the location that Sublime will default to (your User package):
import sublime
import sublime_plugin
class ToggleWhiteSpaceCommand(sublime_plugin.TextCommand):
def run(self, edit, options=["none", "selection", "all"]):
try:
current = self.view.settings().get("draw_white_space", "selection")
index = options.index(current)
except:
index = 0
index = (index + 1) % len(options)
self.view.settings().set("draw_white_space", options[index])
The defined command takes an optional argument named options which allows you to specify the values that you want to toggle between, with the default being all of the possible options.
You can bind a key directly to the command to toggle the state of the setting between all of the possible values of the setting, or use something like the following if you only want to swap between it always being on and always being off, for example:
{
"keys": ["super+s"],
"command": "toggle_white_space",
"args": {
"options": ["all", "none"]
}
},
Note that although this is changing the setting, it's applying the setting directly to the currently focused view, which is persistent but only to the view in question and only as long as that view is open. This doesn't alter the setting for other files that are already open or for any new files that you might open in the future; the default for such files will still be what you have the setting set to in your user preferences.
Using LWUIT framework to develop mobile application.
In LWUIT by default first command is placed in the left and subsequent commands will be placed in the right menu of the form including the command which is already placed in form left.I need to add two menus to form.Left menu contains general application specific commands such as "Minimize","Back" and "Exit". Right Menu contains screen specific commands such as "Play Audio","Play Video" etc... Initially left softbutton of the form contains the text "Options" and the right softbutton of the form contains the text "Menu". When user selects "Options", a menu will be displayed with the following commands:
Minimize
Back
Exit
When user selects right soft button "Menu", a menu will be displayed with screen specific commands:
Play Audio
Play Video etc...
Commands of the right menu keeps changing from one form to another form, whereas the commands of left menu remains the same for all screens(forms). I know command menu can be customized by overriding "Form.createCommandList(Vector)" which returns a list. But here in my case I need two lists(menus). One at the left of the form and the other one at the right of the form.Please do help me in resolving this issue.
A LWUIT menu is just a dialog containing a List (or buttons for touch menu or pretty much anything you want), so to implement this just create a Command called options and place it in the left soft button. When options is pressed just show the dialog with your "additional commands". Since a List can accept a command array or vector doing something like this can be really easy.
You can look at the code for MenuBar which is pretty simple, you can also replace the menu bar component in the latest version LWUIT (SVN at the moment) but that seems redundant for this particular use case.