如何在 Xcode 中缩进多行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/829954/
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 03:00:55  来源:igfitidea点击:

How can I indent multiple lines in Xcode?

xcodecode-formatting

提问by Thanks

When I select multiple lines of code and want to indent them as usual with TABkey, it just deletes them all. I come from Eclipse where I always did it that way. How's that done in Xcode? I hope not line by line ;)

当我选择多行代码并想像往常一样用TAB键缩进时,它只会将它们全部删除。我来自 Eclipse,我总是那样做。这在 Xcode 中是如何完成的?我希望不是一行一行;)

回答by JWD

The keyboard shortcuts are ?+]for indent and ?+[for un-indent.

键盘快捷键是?+]表示缩进,?+[表示取消缩进。

  • In Xcode's preferences window, click the Key Bindings toolbar button. The Key Bindings section is where you customize keyboard shortcuts.
  • 在 Xcode 的首选项窗口中,单击 Key Bindings 工具栏按钮。Key Bindings 部分是您自定义键盘快捷键的地方。

回答by JavierGiovannini

Select your code to reindent, then Go to

选择要重新缩进的代码,然后转到

Editor -> Structure -> Re-Indent

编辑器 -> 结构 -> 重新缩进

回答by Nik

?+ [and ?+ ]are the equivalents to shift+tabin Xcode.

?+[?+]shift+tabXcode中的等效。

回答by swiftBoy

Here are the shortcuts, to format the code in XCode

这是在 XCode 中格式化代码的快捷方式

  1. Format entire code (entire class/controller)

    Select the entire code and press control+Ion macto format your code.

  2. Format particular block of code

    Select the code and press:

    • ?+]for right move (indent)
    • ?+[for left move (un-indent)
  1. 格式化整个代码(整个类/控制器)

    选择整个代码并在 Maccontrol+I来格式化您的代码。

  2. 格式化特定的代码块

    选择代码并按:

    • ?+]右移(缩进)
    • ?+[左移(取消缩进)

Note: as per @JavierGiovannini sugesstion you can do using Editor Menu option

注意:根据@JavierGiovannini sugesstion,您可以使用编辑器菜单选项

  1. Select your code and navigate to Editor > Structure > Re-Indent
  1. 选择您的代码并导航到编辑器 > 结构 > 重新缩进

回答by Joel

Another way to quickly reformat indenting is a quick cut and paste. ?+xand ?+v. I often find it faster than ?+[or ?+]as you can do it with one hand (versus two) and it will reformat to the correct indent level in one shot.

另一种快速重新格式化缩进的方法是快速剪切和粘贴。?+x?+ v。我经常发现它比?+[?+更快,]因为你可以用一只手(而不是两只手)完成它,并且它会在一次拍摄中重新格式化为正确的缩进级别。

回答by Chowdhury Md Rajib Sarwar

First, select all code using command+a

首先,使用command+选择所有代码a

Second, hold key ctrand then press i

二、按住键ctr再按i

the whole selected code will nicely indent.

整个选定的代码将很好地缩进。

回答by MaxEcho

If you use synergy (to share one keyboard for two PCs) and PC(MAC) in which you are using xcode is slave, and master PC is Windows PC

如果您使用协同(为两台 PC 共享一个键盘)并且您使用 xcode 的 PC(MAC)是从属的,并且主 PC 是 Windows PC

keyboard shortcuts are alt+]for indent and alt+[for un-indent.

键盘快捷键是alt+]表示缩进,alt+[表示取消缩进。

Update:

更新:

But from synergy version 1.5 working ?+[for indent and ?+]for un-indent

但是从协同版本 1.5 工作?+[用于缩进和?+]用于取消缩进

回答by phatmann

In Xcode 9, you can finally use Tab and Shift+Tab to indent multiple lines of code. Yay!

在 Xcode 9 中,您最终可以使用 Tab 和 Shift+Tab 来缩进多行代码。好极了!

回答by hariseldon78

Select "Tab key: Indents always" in Preferences->Text Editing->Indentation Then you can indent a single line or a selection of lines by pressing TABor SHIFT+TABSadly this removes altogether the possibility to insert tabs where you want, and conflict badly with the tab key being used to switch between "autocompletion fields".

选择“Tab键:缩进总是”在首选项- >文本Editing->压痕然后你就可以缩进单行或按选择行TABSHIFT+TAB可悲的是这消除了完全插入你想要的标签的可能性,以及冲突与严重用于在“自动完成字段”之间切换的 Tab 键。

I guess we need more tab keys in the keyboard, one is not enough...

我想我们在键盘上需要更多的 Tab 键,一个是不够的......

回答by Neimsz

To all frenchs Xcoders around, the default keybindings are as follow :

对于周围的所有法国人 Xcoders,默认的键绑定如下:

Indent selection:

缩进选择:

?+ ?+ ?+ )

?+ ?+ ?+)

Unindent selection:

缩进选择:

?+ ?+ ?+ (

?+ ?+ ?+(