douyin6188
douyin6188
2018-04-25 16:44

如何修复Sublime Text 3中项目的不一致缩进?

已采纳

I notice one of the file in my PHP Laravel project kept showing weird lines indetation in my Sublime Text 3.

Both file in the same project, but I am not sure one show a lot more line than other.

Is there a way to fix this in Sublime? Is there a way to fix the file indentation?

enter image description here

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doty58493 doty58493 3年前

    In situations where files don't seem to have the indentation that you would expect them to have based on your settings, the culprit is generally this setting:

    // Set to false to disable detection of tabs vs. spaces on load
    "detect_indentation": true,
    

    This defaults to being turned on, which makes Sublime attempt to detect the indentation of a file when you open it. The detection can cause it to assume that the file should use tabs instead of spaces (or vice versa), as well as making it think the tab_size is not what you expect.

    In your screenshot it looks like at a minimum the second is what's happening to you; the tab size looks like it's set to 2 instead of 4.

    If you watch the status line when you open a file, you can see it generating a message there like Detect Indentation: setting indentation to 2 or something along those lines.

    The specifics for how the auto-detection works can be found in the detect_indentation.py plugin in the Default package, but roughly speaking it determines the indentation by seeing how many lines are indented with tabs versus with spaces as well as checking for common indent sizes.

    Turning the setting off and re-opening the file clears the problem in most cases. If that still doesn't solve the problem because the indent is stuck at the old level, you may need to avail yourself of the Convert Indentation commands that you can find in the menu that opens when you click on the part of the status line that tells you how it's indenting things.

    点赞 评论 复制链接分享

相关推荐