How to auto-indent code in the Atom editor?

后端 未结 11 1511
野的像风
野的像风 2020-12-07 07:04

How do you auto-indent your code in the Atom editor? In other editors you can usually select some code and auto-indent it.

Is there a keyboard shortcut as well?

11条回答
  •  没有蜡笔的小新
    2020-12-07 07:25

    On Linux

    (tested in Ununtu KDE)

    There is the option in the menu, under Edit > Lines > Auto Indent or press Cmd + Shift + p, search for Editor: Auto Indent by entering just "ai"

    Note: In KDE ctrl-alt-l is already globally set for "lock screen" so better use ctrl-alt-i instead.

    You can add a key mapping in Atom:

    • Cmd + Shift + p, search for "Settings View: Show Keybindings"
    • click on "your keymap file"
    • Add a section there like this one:

       'atom-text-editor':
          'ctrl-alt-i': 'editor:auto-indent'
      

    If the indention is not working, it can be a reason, that the file-ending is not recognized by Atom. Add the support for your language then, for example for "Lua" install the package "language-lua".

    If a File is not recognized for your language:

    • open the ~/.atom/config.cson file (by CTRL+SHIFT+p: type ``open config'')
    • add/edit a customFileTypes section under core for example like the following:

      core:
        customFileTypes:
          "source.lua": [
            "conf"
          ]
          "text.html.php": [
            "thtml"
          ]
      

    (You find the languages scope names ("source.lua", "text.html.php"...) in the language package settings see here)

提交回复
热议问题