How to enable auto-align in Sublime Text 3? - sublimetext3

I want to auto-align my code to make it easier to read, in a click. I am working on Sublime Text 3 and want to know about a method through which I can enable auto-indent of the code in just a click.

I'd recommend the AlignTab extension: https://github.com/randy3k/AlignTab (with Demo)

By using the https://github.com/randy3k/AlignTab package, you can activate the Table Mode which constantly aligns the code for you, until you run the command Exit Table Mode, for example:

{"keys": ["f12"], "command": "reindent", "args": {"single_line": false}}

In the title bar, go to Preferences > Key Bindings, then add this binding to "Key Bindings - User" file.
{"keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false}}
Now whenever you want to auto-align your code, just highlight the desired code and press alt+shift+f
Source: https://coderwall.com/p/7yxpdw/auto-indenting-on-sublime-text-3
Note: This was the original answer from the OP #Utkarsh (with score 18) that OP deleted and edited into the question.

Related

Sublime Text 3 Shortcut Find and Replace won't work

I've found several topics related to my issue, but they didn't work. In Sublime Text 3, my macOS super+alt+f "find and replace shortcut" (raise the panel of find/replace) doesn't work. I already tried:
running "FindKeyConflicts: All key conflicts":
(super+l,alt+super+f)
latex_fill_all LaTeXTools
[{"operand": "text.tex.latex", "operator": "equal", "key": "selector"}]
an then put the following into Preference > Key Bindings (User):
{"keys": ["super+alt+f"], "command": "show_panel", "args": {"panel": "replace", "reverse": false}}
This is how to resolve your Sublime Text key binding conflict.
Install the BoundKeys package.
Run BoundKeys by selecting List bound keys from the Command Palette.
BoundKeys will create a new buffer (unsaved file) which lists all of your key bindings on a file by file basis, i.e. all the .sublime-keymap files that ST has loaded.
Have a look at this BoundKeys example output. The example has been heavily edited, enough so that you can easily see the essential components.
The keys from each .sublime-keymap file are shown, with the highest precedence (highest priority) file at the top, while those from the file with the least precedence (lowest priority) are shown last.
In the example output have a look at the bottom line in the top .sublime-keymap file, the User package. shift+f10 has been assigned to the context_menu command, the right-hand column shows that there is a conflict with the ChooseWindow package. Look a little down and you'll see the corresponding line in the ChooseWindow package - the shift+f10 line shows a conflict with *User*. The *asterisks* show that this key binding has been overwritten by the one in the User package.
Now search your BoundKeys output for Super+Alt+F. You should be able to tell where the key conflict is and it should be fairly easy to see how to resolve the conflict.
Note that you may have to search for Alt+Super+F as well. It should be clear that Super+Alt+F and Alt+Super+F are the same key binding but not the same text.
I hope this answer will help if you run into the same issue, because it's a bit tricky. The issue is a small App I use which used the shortcut above.
It's clear there is a Shortcut I didn't find at start. With this information I just changed the following within Preferences > Key Bindings:
{
"keys": ["super+shift+alt+f"], "command": "show_panel", "args": {"panel": "replace", "reverse": false}
}

Sublime Text 3 disable SHIFT+Delete copying the selected text

Is it possible to disable this behaviour? It's possible in Visual Studio but I would like to change this also on ST3.
I think that the original question is not about removing the functionality of shift+delete, but only removing the copy function from it. So I'd like to post my answer here in case somebody would be looking for specifically this.
I found right_delete, mentioned in the comments, to be rather inconvenient, because you would need your cursor to be at the beginning of the line in order to work. I found that line deletion is set to ctrl+shift+k by default (on Windows), so I just used its macro for shift+delete.
So here's the line I added to my Preferences > Key Bindings:
{ "keys": ["shift+delete"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
This way you don't need to worry about the position of your cursor, as long as it's within the wanted line.
On Windows/Linux, the Default key bindings map Shift+Delete to the cut command:
{ "keys": ["shift+delete"], "command": "cut" },
In order to disable that behaviour, you can select Preferences > Key Bindings from the menu, and add the following to the binding to the right hand pane:
{ "keys": ["shift+delete"], "command": "noop" },
Alternately you can replace noop with some other command that you would rather perform in this case instead, should you want to use the key for something else.

How can I set key bindings for show and hide Sublime Text line numbers?

I am trying to build a new key binding on Sublime Text to show or hide the line numbers.
Do somebody know how to do it?
The setting used to show or hide line numbers is line_numbers. For instance, setting line_numbers: false in your User preferences file would permanently hide line numbers.
Now to answer your question, to toggle a setting, you can add the following to your User keybindings file:
{
"keys": ["ctrl+l"],
"command": "toggle_setting",
"args":
{
"setting": "line_numbers"
}
}
You can change ctrl+l to whatever keys you want.
If you ever want to toggle any other setting in the future, you can just use this exact code, but you would just have to change the "line_numbers" to the name of the setting you want to toggle.

Can I emulate arrow key in sublimetext3?

In short:
I want to type [left arrow], [right arrow], [command-v] sequence whenever I press [command-v] in sublime text 3.
In length: I have a problem with IME and pasting in sublime text (OSX). If you don't use asian language you might not understand what I'm saying but let me try.
I'm korean. My language has letters like '각' and '가'. Do you notice the difference? The prior letter have additional 'ㄱ' at its bottom.
To type in those letters, you press 'ㄱ' -> 'ㅏ' -> 'ㄱ' for prior, and 'ㄱ' -> 'ㅏ' for latter. Again, do you notice the difference?
To complete the letter '각', you should make the letter '가' first, and type in additional 'ㄱ'. However, you want '가' this time, so typed 'ㄱ' -> 'ㅏ' and completed the letter '가', but sublime (or OSX IME) doesn't know whether you completed, or should wait for the additional ㄱ to complete the letter '각'. So it awaits next type to decide to start new letter, or to complete something like '각'. My problem begins here.
You completed the letter and want to paste something, so press [command-v], but sublime was waiting for additional component and did not finish the letter. It just deletes the letter '가'. To work around this problem, I type in something like [space] or [arrow key] to make sure sublime completes the letter. This is fairly annoying.
So, I want to automate the annoying potion. Can I type [left arrow], [right arrow], [command-v] sequence whenever I press [command-v] in sublime text 3? [space], [backspace], [command-v] or any combination will work, I think.
Any help will be highly appreiciated
I think a solution to your dilemma could be to create a macro. To do this, look in Tools -> Record Macro, which you'll also notice is triggered by Ctrl + Q. Once you activate that, perform the key combination you wish to invoke. In this case, the sequence:
Left Arrow
Right Arrow
Ctrl + V
Now go back into Tools -> Stop Recording Macro. Now, it won't be explicitly saved yet - your macro is now placed on the buffer, and you can play it back with Tools -> Playback Macro. To save it for continued use, use Tools -> Save Macro... and save it somewhere (most commonly in .../Packages/User, although by no means do you need to save it here).
For reference sake, your macro should look exactly like this:
[
{
"args":
{
"by": "characters",
"forward": false
},
"command": "move"
},
{
"args":
{
"by": "characters",
"forward": true
},
"command": "move"
},
{
"args": null,
"command": "paste"
}
]
That text was generated by following my steps exactly and recording the macro appropriate to your situation.
And to use this macro, we'll need to do a little more tinkering.
Look in Preferences -> Key Bindings - User. This will open a rather derelict text file (assuming you haven't touched it yet) where you can specify your own keyboard mappings. These will override the default settings (located in Preferences -> Key Bindings - Default, if you wish to check those out).
So in this "User" key bindings file, we need to specify that the normal Ctrl + V will be overridden by our custom macro. An empty "User" key bindings file will look like this:
[
]
Not much to extrapolate from. The syntax required here is fairly legible, but pretty difficult to guess at without prior knowledge. Add this entry between those brackets, like so:
[
{
"keys": ["ctrl+v"], "command": "run_macro_file", "args": {"file": "path/to/your/<macro_name>.sublime-macro"}
}
]
Save that file, and you should be good to go. You may need to restart Sublime for this to take effect.

How to add text before and after selection in Sublime Text?

How can I make a shortcut, so that my selected text is wrapped with special characters?
For example:
For teaching HTML, I'd like to show some tags in plain text. When selecting span I'd like to wrap the selection with < and >.
How can I do this?
Create a snippet in your User directory tag.sublime-snippet:
<snippet>
<content><![CDATA[
<$0$SELECTION>
]]></content>
</snippet>
Save and make a new key binding in your User keybindings
{ "keys": ["ctrl+t"], "command": "insert_snippet", "args": { "name": "Packages/User/tag.sublime-snippet" } },
Though the best way to do this is to simply use Search and replace the left < to < and then > to >
Might be a bit overkill for what you are trying to do, but take a look at BracketHighlighter. Specifically, the bracket wrapping functionality. Will take some configuration on your part, but saves you the trouble of writing your own plugin.

Resources