Using Sublime Text 3 (Build 3059) on Linux.
In Sublime Text column selection can be used to select a rectangular area of a file. When using the mouse to do this different mouse buttons are used on each platform. On both OS X and Windows the middle mouse button can be used to select the rectangle of text. On Linux you need to use the right mouse button + shift, I find that combination inconvenient so instead wanted to use the 4th button on my mouse to do it without the hassle of a modifier key.
Easy enough I just need to change the column selection mouse mapping in my default mousemap file.
Here are the relevant sections of the 3 (Linux, OS X, and Windows) default mousemap files:
// Column select Linux default mousemap file
{
"button": "button2", "modifiers": ["shift"],
"press_command": "drag_select",
"press_args": {"by": "columns"}
},
// Column select is the same in the default OS X and Windows mousemap files:
{
"button": "button3",
"press_command": "drag_select",
"press_args": {"by": "columns"}
},
So I figured all I needed to do is to use the same code as OS X and Windows but to set "button4" instead of "button3". So I ended up with this:
// ~/.config/sublime-text-3/Packages/User/Default (Linux).sublime-mousemap
[
// Map column select to 4th mouse button.
{
"button": "button4",
"press_command": "drag_select",
"press_args": {"by": "columns"}
}
]
All very logical and straightforward except that it does not work. Pressing the 4th mouse button does not do column selection, it just does nothing. What's wrong?!
It took me a while to figure this out but...
In Linux the 4th mouse button is not necessarily referenced by "button4". In fact on my system the 4th mouse button is referenced by "button8". All that was needed was to use "button8" where before I had used "button4".
[
// Map column selection to 4th mouse button ("button8").
{
"button": "button8",
"press_command": "drag_select",
"press_args": {"by": "columns"}
}
]
Hope this helps someone.
EDIT: UNIX/Linux users can use xev, which prints the contents of X events, to get their mouse button numbers.
Related
There are keyboard shortcuts to select everything between matching brackets and to grow and shrink your selecting, however sometimes there is another markup inside. Is there a way to select everything from coursor to beginning of the next element? For example the cursor sits after the tag. When pressing shortcut I want to:
<p>Select only this text<span>and not this</span>, also not this.</p>
Thank you
You can use the extension Select By.
In your settings.json
"selectby.regexes": {
"till-angle-bracket": {
"forward": "<",
"forwardInclude": false
}
}
You can use the command Select text range based on regex and select till-angle-bracket from the list
or you can add a keybinding
{
"key": "ctrl+shift+y", // or any other key-combo
"when": "editorTextFocus",
"command": "selectby.regex",
"args": ["till-angle-bracket"]
}
I am trying to use the Sublime Text Plugin RegReplace package so I can highlight a line of text and replace spaces with dashes.
Goal
Hello My Name is Jesse, Highlight, CTRL + . replaces with:
Hello-My-Name-is-Jesse -- for the purpose for saving time creating markdown links.
Currently Working, But Runs Entire File
I would really like this to only replace the text I have highlighted wit a hotkey, is this possible?
I have this in reg_replace_rules.sublime-settings
{
"replacements": {
"replace_spaces_with_dash": {
"find" : "(\\s)",
"replace": "-",
"greedy": true,
"case": false
}
}
}
Here is my User Hotkeys
{
"keys": ["ctrl+."],
"command": "reg_replace",
"args": {"replacements": ["replace_spaces_with_dash"]}
},
However, this replaces the entire file with spaces. I am missing something I hope, I am not sure the scope. Any help would be appreciated.
u undos except if you have something selected. Then it turns selection into lower case.
Is there any way to turn of "to lower case" and have u doing undo no matter if you've selected some text or not?
You can simply add a Key Binding to "Key Bindings - User" for the desired key combination that will supersede the default.
On OS X I would go to:
Sublime Text
...Preferences
......Key Bindings - User
On Windows/linux (thanks #MattDMo)
Preferences
...Key Bindings - User
Then I'd add in a new key binding specific to what I want it to do.
If I want to change command + o from open a file to undo I would add
{ "keys": ["command+o"], "command": "undo" }
With that command + o would now undo for me.
More details here: http://docs.sublimetext.info/en/latest/customization/key_bindings.html
You should be able to edit your key bindings to do this. however if you want to turn off vintage altogether, then,
Select the Preferences/Settings - Default menu item
Edit the ignored_packages setting, change it to:
"ignored_packages": ["Vintage"]
There is a guide to remapping keybindings here
here is an example
[
{ "keys": ["j", "j"], "command": "exit_insert_mode",
"context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
]
In Sublime Text 3 Vintage Mode, the keyboard shortcut "}" performs the following command:
{
"keys": ["}"],
"command": "set_motion",
"args": {
"motion": "move",
"motion_args": {
"by": "stops",
"empty_line": true,
"extend": true,
"forward": true,
"separators": "",
"word_begin": false
}
}
}
I can't find good documentation for set_motion and I'm not sure where to start to implement this from scratch.
How do I change the behavior so that instead of moving to the next empty line, it moves to the next line with only whitespace?
Thanks!
Can't really help with the set_motion command, but doing it yourself via a plugin shouldn't be to bad. First off, here is a link to the ST3 API docs. You will be creating a sublime_plugin.TextCommand. Of particular interest are view#sel, view#line, and view#substr.
view#sel will get you the position of the cursor(s).
view#line with a point passed in (initially retrieved from view#sel) will create give you a region of the entire line.
view#substr takes the region (result from view#line) and returns the string of the characters in that line. You can use a regular expression to see if that line contains only white space, and place the cursor appropriately. If the line does not meet the requirement, you can increase the second point in the region to move to the next line.
Hope that helps getting you moving in the right direction.
Here is a comment from the softwares author on the options availability for “by”: “stops”
https://forum.sublimetext.com/t/restoring-st2-cursor-move-by-word-behaviour-in-st3-on-os-x/14035
If you need more control, then using the move command with “by”: “stops” should allow more configurability. When using stops, you need to tell the command which logical units to stop on. The options are:
"word_begin": false,
"word_end": false,
"punct_begin": false,
"punct_end": false,
"sub_word_begin": false,
"sub_word_end": false,
"line_begin": false,
"line_end": false,
"empty_line": false,
How can I scroll up and down a file using my keyboard? I tried the arrow keys plus different modifiers.
If you look at the default key binding for the program (on Mac version, this is in the menu "Sublime Text 2/Preferences/Key Bindings - Default"), you can see what all the keyboard shortcuts are.
I did a find for "scroll" and found these lines:
{ "keys": ["ctrl+alt+up"], "command": "scroll_lines", "args": {"amount": 1.0} },
{ "keys": ["ctrl+alt+down"], "command": "scroll_lines", "args": {"amount": -1.0} },
So, ctrl+alt+up and ctrl+alt+down will scroll the view up and down 1 line at a time. If you want to change this, copy these lines into your "Key Bindings - User" file and change the corresponding parts of the line.