Indentation Error with Sublime Text

前端 未结 2 1323
礼貌的吻别
礼貌的吻别 2021-02-03 13:57

I\'m trying to use the auto-indentation feature in Sublime Text 3 for HTML. I\'ve got some block comments in the html and selecting Edit>Line>Reindent works until it hits a bloc

2条回答
  •  暖寄归人
    2021-02-03 14:49

    I have logged the issue here: https://github.com/SublimeTextIssues/Core/issues/1271

    The reason for this behavior is because Sublime Text, by default, is set to preserve the indentation of comments. To disable this:

    1. Install Package Control if it is not already installed
    2. Install PackageResourceViewer if it is not already installed:
      • Open the Command Palette
      • Select Package Control: Install Package
      • Select PackageResourceViewer
    3. Open the Command Palette
    4. Type PRV: O
    5. Select PackageResourceViewer: Open Resource
    6. Select Default
    7. Select Indentation Rules - Comments.tmPreferences
    8. Change the under preserveIndent to
    9. Save the file

    Reindentation will now work correctly with comments.


    I would also recommend to edit the HTML indentation rules to ignore comments, so that it doesn't change indentation based on tags in comments. i.e. otherwise

    
    
    Testing Indent
    
    
    
    Cell 2
    
    Cell 1

    would become:

    
    
        Testing Indent
    
    
        
                Cell 2
                
    Cell 1

    To do this:

    1. Open Command Palette
    2. Type PRV: O
    3. Select PackageResourceViewer: Open Resource
    4. Select HTML
    5. Select Miscellaneous.tmPreferences
    6. Change

      scope
      text.html
      

      to

      scope
      text.html - comment
      

      and

      |-->
      

      to

      (?#|-->)
      

      (this comments out the closing comment regex)

    7. Save it

    However, when the next release of ST3 is available, it might be a good idea to then delete your overrides, in case it is fixed properly. This way, you will continue to get updates to these files, otherwise you will be stuck with the versions you have saved. To do this:

    1. Preferences -> Browse Packages
    2. Delete the HTML folder
    3. Go into the Default folder and delete the Indentation Rules - Comments.tmPreferences file

    If the problem wasn't fixed in the next build, you can simply recreate these changes.

提交回复
热议问题