如何在 Xcode 中获得智能标签(“用标签缩进,与空格对齐”)行为?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16208065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:48:04  来源:igfitidea点击:

How to get smart tabs ("indent with tabs, align with spaces") behavior in Xcode?

xcodecoding-stylealignmentindentation

提问by FreeNickname

I used to use tabs for indentation and spaces for alignment. Like so (arrows show tabs and dots show spaces).

我曾经使用制表符进行缩进,使用空格进行对齐。像这样(箭头表示制表符,点表示空格)。

enter image description here

在此处输入图片说明

In QtCreator you can set such coding style in standard preferences. I can't find the way to achieve the same goal in Xcode. Could you please tell me if it is possible? May be there is a plugin for that?

在 QtCreator 中,您可以在标准首选项中设置此类编码风格。我找不到在 Xcode 中实现相同目标的方法。你能告诉我是否可能吗?可能有一个插件吗?

UPDATE:Here is how it can be achieved in QtCreator: enter image description here

更新:这是在 QtCreator 中实现的方法: 在此处输入图片说明

P.S. Please, don't try to persuade me that using spaces only/tabs only is better, otherwise this question will turn into another holywar :)

PS请不要试图说服我只使用空格/制表符更好,否则这个问题将变成另一个圣战:)

Once more about what I'm trying to achieve: Indent with tabs, align with spaces. Vim Tips Wiki.

再次说明我要实现的目标:使用制表符缩进,与空格对齐。Vim 技巧维基

UPDATE 2:I've just submitted an Apple Radar bug-report (enhancement) rdar://22285639. Here it is on the open radar.

更新 2:我刚刚提交了 Apple Radar 错误报告(增强)rdar://22285639。这是开放式雷达

UPDATE 3:I received an answer from Apple. My bug is a duplicate of rdar://8165023.

更新 3:我收到了 Apple 的答复。我的错误是 rdar://8165023 的副本。

回答by Undo

In Xcode > Preferences (?,):

在 Xcode > 首选项 ( ?,) 中:

>Text Editing >Indentation

>文本编辑 >缩进

If I understand your question correctly, this should do it for you.

如果我正确理解你的问题,这应该为你做。

回答by OlDor

If you want to remap the standard Xcode's ?+[to TAB, you can do the following:

如果要将标准 Xcode 的?+重新映射[TAB,可以执行以下操作:

  1. Install a program called "Karabiner".

  2. Go to Preferences ~> "Misc and Uninstall"

  3. In "Custom Setting" section click on the "Open private.xml" button

  4. Open the file and replace its content with the following code:

    <?xml version="1.0"?> 
    <root>
        <item>
            <name>Tab instead of Command+[</name>
            <identifier>private.swap_tab_and_cmnd+[</identifier>
            <autogen>
                __KeyToKey__
                KeyCode::TAB, ModifierFlag::NONE,
                KeyCode::BRACKET_RIGHT, ModifierFlag::COMMAND_L | ModifierFlag::NONE
            </autogen>
        </item> 
    </root>
    
  5. Go to Preferences ~> "Change Key" ~> click on "Reload XML" button

  6. Put a tick in the checkbox which is called "Tab instead of Command+["

  7. Enjoy

  1. 安装一个名为“Karabiner”的程序。

  2. 转到首选项 ~>“杂项和卸载”

  3. 在“自定义设置”部分单击“打开 private.xml”按钮

  4. 打开文件并将其内容替换为以下代码:

    <?xml version="1.0"?> 
    <root>
        <item>
            <name>Tab instead of Command+[</name>
            <identifier>private.swap_tab_and_cmnd+[</identifier>
            <autogen>
                __KeyToKey__
                KeyCode::TAB, ModifierFlag::NONE,
                KeyCode::BRACKET_RIGHT, ModifierFlag::COMMAND_L | ModifierFlag::NONE
            </autogen>
        </item> 
    </root>
    
  5. 转到首选项 ~>“更改密钥”~> 单击“重新加载 XML”按钮

  6. 在名为“Tab 而不是 Command+[”的复选框中打勾

  7. 享受

enter image description here

在此处输入图片说明

PS: Please note that this setting works globally on your machine, not just in Xcode. However, I am sure that google might help you to find a solution how to customize it even further, applying the changes only to Xcode.

PS:请注意,此设置在您的机器上全局有效,而不仅仅是在 Xcode 中。但是,我相信 google 可能会帮助您找到如何进一步自定义它的解决方案,仅将更改应用于 Xcode。

回答by Sultan Ali

In XCode
Xcode > Preferences or use ? ,to open Preferences
now click on the Text Edittab and then there is sub tab bar click on Indentationand you can change setting of the Indentationas you need

在 XCode
Xcode > Preferences 或用于? ,打开Preferences
现在单击Text Edit选项卡,然后单击子选项卡栏Indentation,您可以Indentation根据需要 更改设置

here is the last view for the preferences

这是首选项的最后一个视图