Is there any shortcut to indenting code in Sublime 3?

13

It is noticeable that in several IDE's there are some shortcuts to indent the code . For example:

    Eclipse (Win): Ctrl + Shift + F

As everyone knows, I assume, the indentation visually organizes the code so that the dependent blocks are aligned, making it easier to understand and read.

An example of the code below undetermined :

          <div class="navbar-header">
                <button type="button" 
class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
               <span class="sr-only">Toggle navigation</span>
                       <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="index.html">SB Admin</a>
</div>

Now with indent :

<div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="index.html">SB Admin</a>
</div>

Is there a shortcut or "worm" to indent the code in Sublime 3?

    
asked by anonymous 21.01.2017 / 20:27

3 answers

20

Just add this line to your "Key Bindings - User" file (located in Preferences & Keybindings - User)

{"keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false}}

Source: link

List of arguments: link

    
21.01.2017 / 20:31
8

It is not by default a shortcut to this command (at least it did not come).

What you can do is add a custom shortcut: Preferences - > Key bindings , and in the right tab (custom), add something like this:

{ "keys": ["ctrl+shift+r"], "command": "reindent"}

So here's mine: I use a lot of ctrl+shift+r for reindentation when I paste an out code (you have to adjust the language before to work with a new unsaved file).

Another way is to use the command ctrl+shift+p ( goto anything , one does everything), which I use a lot too. You enter part of the command ( reindent , word wrap ) and it shows the options.

    
21.01.2017 / 20:34
2

Good night everyone

 var in the Preferences - > Key bindings

 You will see two tabs on the right (custom) tab, you enter the code below.

    {"keys": ["ctrl + k + d"], "command": "reindent"} or another one of your taste, if it is another, check if there is this command on the right side. in my case your I press only to type ["ctrl + d"] it identa,

obs: For the code to be indented you have to select it, it is not like other IDEs that you do not need to select the code. Hope this helps.

Just below a gif with the example used.

    
29.12.2017 / 03:07