Pregunta

En Visual Studio puedo presionar Control+k+D sangrar todo para que el código esté bien estructurado y sea legible.¿Existe un atajo en Sublime 2 para hacer lo mismo?

¿Fue útil?

Solución

Puedes encontrarlo en EditLineReindent, pero no tiene un acceso directo por defecto.Puedes agregar un acceso directo yendo al menú. PreferencesKeybindingsUser, luego agregue allí:

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

(ejemplo de uso del F12 clave para esa funcionalidad)

Los archivos de configuración usan sintaxis JSON, por lo que estas llaves deben colocarse separadas por comas en los corchetes que están ahí de forma predeterminada.Si aún no tienes otras combinaciones de teclas, entonces todo tu KeybindingsUser El archivo se vería así, por supuesto:

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

Otros consejos

El comando RESULTE solo funciona en las líneas seleccionadas actualmente a menos que el argumento "single_line" esté configurado en FALSO.

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

Ahora, al presionar F12 renunciará a todo el documento.

Nadie parece amar a Mac Re-Indentation, así que aquí lo hago:

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

En Preferencias> Encuadernación de teclas - Usuario

Uno más adicional: Añadir

{ "keys": ["command+0"], "command": "focus_side_bar" }

Tener la navegación de la vista de árbol de archivos de la barra lateral usando el teclado.

NOTA: Agregue, al final de cada {}, si tiene más de un conjunto {} de objetos

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:

  1. Control+Shift+P (or +Shift+P on a Mac)
  2. Type the first few characters of Reindent e.g: rein
  3. 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:

enter image description here

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 PreferencesKeybindingsUser, 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

First open the sublime text.
than open preferences.
than open Key Bindings -User.
than put the below code

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

I use Ctrl+Shift+C and you also use other short cut key.

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top