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.
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.
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 }
]
}
]
{
"keys": ["control+shift+a"], "command": "align_tab",
"args" : {"user_input" : ":/f"}
}
I'm attempting to bind Control+Shift+A to the "align colons" command of the SublimeText plugin "AlignTab"... but this keybind isn't working, despite it being a near copy paste of what's in their tutorial.
Anyone have any idea? What am I doing wrong?
Reference: https://github.com/randy3k/AlignTab
I think that Ctrl+Shift+A might already be bound to another command. In my default keybinds file, it shows that:
{ "keys": ["ctrl+shift+a"], "command": "expand_selection", "args": {"to": "tag"} },
Other than that, your syntax checks out, so I'm not sure how that could break.
In Visual Studio I can press Ctrl+K+D to indent everything so the code is structured nicely and readable. Is there a shortcut in Sublime 2 to do the same?
You can find it in Edit → Line → Reindent, but it does not have a shortcut by default.
You can add a shortcut by going to the menu Preferences → Keybindings → User, then add there:
{ "keys": ["f12"], "command": "reindent", "args": {"single_line": false} }
(example of using the F12 key for that functionality)
The config files use JSON-syntax, so these curly braces have to be placed comma-separated in the square-brackets that are there by default. If you don't have any other key-bindings already, then your whole Keybindings → User file would look like this, of course:
[
{ "keys": ["f12"], "command": "reindent", "args": {"single_line": false}}
]
The reindent command only works on the currently selected lines unless the "single_line" argument is set to false.
{ "keys": ["f12"], "command": "reindent", "args": {"single_line": false} }
Now, pressing f12 will reindent the entire document.
No one seems to love mac re-indentation, So here How I do it:
[
{ "keys": ["command+shift+i"], "command": "reindent"}
]
In Preferences > Key Binding - User
One more extra tip:
add
{ "keys": ["command+0"], "command": "focus_side_bar" }
to have sidebar file tree view navigation using keyboard.
Note:
Add , at the end of each {}, if you have more than one {} set of objects
There is no default shortcut for reindenting a file. However you can create one by following eznme's answer above.
You can also use the Command Palette by pressing:
Control+Shift+P (or ⌘+Shift+P on a Mac)
Type the first few characters of Reindent e.g: rein
Press Enter to run the command(The first command at the top should now show Indentation: Reindent Lines)
For those interested it is easy to change but for a lover of Netbeans and the auto-format you can change the key binding from F12 to ctrl+shift+F to use your beloved key binding. Sad part is that you have to select all to format the entire file. Netbeans still has the upper hand on that. If anyone knows how to overcome that limitation I'm all ears. Otherwise happy reindenting (auto-formating).
To indent with the same keys like Visual Studio Ctrl+K+D (I am a Visual Studio user so I am used to this combination) I suggest:
[
{ "keys": ["ctrl+k", "ctrl+d"], "command": "reindent", "args": {"single_line": false} }
]
Write this on Preferences>Key Bindings - User
It is very simple. Just go to Edit=>Line=>Reindent
Netbeans like Shortcut Key
Go to Preferences > Key Bindings > User and add the code below:
[
{ "keys": ["ctrl+shift+f"], "command": "reindent", "args": {"single_line": false} }
]
Usage
Ctrl + Shift + F
Select all code that you intend to indent, then hit Ctrl + ] in Sublime text to indent.
For macOS users, use command + ] to indent, and command + [ to un-indent.
code formatter.
simple to use.
1.Install
2.press ctrl + alt + f (default)
Thats it.
Beside of the inbuilt 'reindent' function, you can also install other plugins, such as SublimeAStyleFormatter and CodeFormatter. These plugins are better for their specify language.
Just in case this stop working for anyone like me, in OS X, the command key is identified as superso it should be able to do something like this:
[
{
"keys": ["super+i"],
"command": "reindent",
"args": {
"single_line":
false}
}
]
in this case using command+i is going to indent your whole code (eclipse like :) )
I used to use Alt + Shift + F in NetBeans, I checked and there isn't any collision in the default keymap array of sublime, so I added it to my sublime and I'm using it without any problem.
For those who like the default key binding for IntelJ IDEA, select Preferences > Settings - User:
And paste in the following to have the command + shift + l shortcut for auto indent:
[
{ "keys": ["command+shift+l"], "command": "reindent"}
]
You can add a shortcut by going to the menu Preferences → Keybindings → User, then add there:
{ "keys": ["f12"], "command": "reindent", "args": {"single_line": false} }
For Auto-Formatting in Sublime Text 2: Install Package: Tag from Command Palette, then go to Edit -> Tag -> Auto-Format Tags on Document
Select everything, or whatever you want to re-indent and do Alt+ E+L+R.
This is really quick and painless.
This is my configuration for sublime-keymap:
[
{
"keys": [",+=+="],
"command": "reindent",
"args": {
"single_line": false
}
}
]
For vim people, just use ,== to reindent the whole file.
{ "keys": ["f12"], "command": "reindent", "args": {"single_line": false} }
You can get the reindent option by using the above code
Steps:
Open Sublime Text.
Open Preferences.
Open Key Bindings -User.
Put below code:
[{"keys": ["ctrl+shift+c"], "command": "reindent"},]
I use CtrlShiftC and you also use other key shortcut.