Atom - 强制选项卡宽度 2 [英] Atom - Force Tab Width 2

查看:30
本文介绍了Atom - 强制选项卡宽度 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了完全开源,我刚刚从 Sublime Text 切换到 Atom.

I just switched from Sublime Text to Atom in order to turn completely open source.

我遇到了一些非常简单的问题:我希望 Atom 始终使用 (!) 并且在任何情况下都使用制表符宽度 2 并用空格替换制表符.这个设置在 gedit 或 Sublime Text 中非常简单,但不管我在尝试什么:当我开始一个新文件时,标签大小是 2(很好!).当我使用现有文件时,标签大小有时是 4.我觉得这有点烦人.

I have trouble with something very very simple: I want Atom to use always (!) and under any circumstances tab width 2 and replace tab with spaces. This setting is so simple in gedit or Sublime Text, but no matter what I am trying: When I start a new file, tab size is 2 (good!). When I use an existing file, tab size is sometimes 4. I find that a bit annoying.

我在编辑器中的当前设置见截图:

My current setting in Editor are seen in the screenshot:

推荐答案

标签设置不止一个

每个包(例如 python-language)都有自己的选项卡设置.语言是使用全局默认值还是它自己的默认值取决于创建包的人,但您通常可以覆盖它.

There is more than one tab setting

Each package (such as python-language) has its own tab setting(s). Whether the language uses the global default or its own default is up to whoever created the package, but you can generally override it.

在您的屏幕截图中,您已将标签类型"设置为软".这将照顾使用空格而不是制表符.您已将默认标签宽度保留为 2.这是您的全局设置.

In your screenshot, you have set the "Tab Type" to "soft". That will take care of using spaces rather than tabs. You have left the default tab width of 2. That is your global setting.

现在,如果您查看Packages"并搜索python",您将找到一个名为language-python"的包.单击其设置按钮,您将找到许多特定于语法的设置.

Now, if you look under "Packages" and search for "python" you will find a package named "language-python". Click on its settings button and you will find a number of syntax-specific settings.

  • Python 语法
  • Python 控制台语法
  • Python 追溯语法
  • 正则表达式 (Python) 语法

每个语法都有自己的制表符长度设置.您可以在此处将它们显式设置为 2 以覆盖包的默认值.(您可能最关心第一个,Python 语法.)

Each of those grammars has its own Tab Length setting. You can set them explicitly to 2 here to override the package's default. (You probably mostly care about the first one, Python Grammar.)

在 Python 的情况下,包被明确配置为默认为 4 个空格,可能是因为 Python 对空格非常自以为是,而 PEP 8 建议缩进 4 个空格.您可以在包的来源中看到默认包设置:

In the case of Python, the package is explicitly configured to default to 4 spaces, probably because Python is very opinionated about whitespace, and PEP 8 recommends 4-space indents. You can see the default package setting here in the package's source:

https://github.com/atom/语言python/blob/master/settings/language-python.cson

'autoIndentOnPaste': false
'softTabs': true
'tabLength': 4

这会覆盖全局默认值.这就是 Python Grammar 不支持全局选项卡宽度的原因,大多数包都是这样做的.

This overrides the global default. That's why Python Grammar does not honor the global tab width, the way that most packages do.

此外,由于语法原因,某些软件包会覆盖您的设置.例如,language-make 将覆盖并使用真正的制表符而不是空格,因为这是制作.

Additionally, certain packages will override your settings for syntax reasons. For example, language-make will override and use real tabs instead of spaces, because that is required by make.

在 Python 的情况下,有使用空格的覆盖.language-python 设置页面为您提供了一个更改缩进级别的位置,但它没有提供切换到使用制表符的方法.(这可能是有道理的,因为 Python 中的制表符和混合缩进是导致难以调试的语法错误的一个非常常见的原因.)

In the case of Python, there is an override to use spaces. The language-python settings page offers a spot for you to change the indentation level, but it does not offer a way to switch to using tab characters. (That's probably justifiable, as tab characters and mixed indentation in Python are a very common cause of difficult-to-debug syntax errors.)

最后,有时设置不会完全生效,直到您重新加载 Atom 窗口.您可以使用 Window: Reload 命令来执行此操作.或者使用键盘:

Lastly, sometimes settings don't take effect completely until you reload the Atom window. You can use the Window: Reload command to do so. Or using the keyboard:

  • Mac:CtrlOptCmdL
  • Windows/Linux:CtrlAltR

这篇关于Atom - 强制选项卡宽度 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆