Is there a shortcut to indenting the code in Sublime 3?

Asked

Viewed 66,206 times

18

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

  • Eclipse(Win): Ctrl + Shift + F

  • Android Studio(Win): Ctrl + Alt + L

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

An example of the code below unedited:

          <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 indented:

<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 "trick" to indent the code in Sublime 3?

3 answers

27


  • Are there other alternatives in the rule for this json that you sent? For example I saw that you have there args, would have other ways of doing following this pattern?

  • @Acklay has a list in the documentation http://docs.sublimetext.info/en/latest/reference/key_bindings.html?highlight=key%20binding

11

Does not come by default a shortcut for this command (at least it didn’t 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"}

Here’s mine: I use a lot of ctrl+shift+r for reindentation when I paste a code from outside (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 type part of the command ( reindent, word wrap) and it shows the options.

4

Go to the menu Preferences -> Key bindings

Two tabs will appear, in the right tab(custom), you inform the code below.

{"keys": ["ctrl+k+d"],"command": "reindent"}

Or another to your liking, if another, check if in the right tab there is this command. In my case if I press only the keys CTRL + D he Indenta.

NOTE: For the code to be indented you have to select, it is not like other Ides that you do not need to select the code. I hope I’ve helped.

Just below a GIF with the example used.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.