如何在 Xcode 中缩进多行?

发布于 2024-07-19 05:00:12 字数 111 浏览 8 评论 0原文

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

When I select multiple lines of code and want to indent them as usual with TAB key, 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 ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

红焚 2024-07-26 05:00:12

键盘快捷键为 +](用于缩进)和 +[(用于取消缩进)。

  • 在 Xcode 的首选项窗口中,单击“按键绑定”工具栏按钮。 “按键绑定”部分是您自定义键盘快捷键的地方。

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.
浴红衣 2024-07-26 05:00:12

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

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

Select your code to reindent, then Go to

Editor -> Structure -> Re-Indent

栩栩如生 2024-07-26 05:00:12

+ [ + ] 相当于 shift+tab Xcode。

+ [ and + ] are the equivalents to shift+tab in Xcode.

帅冕 2024-07-26 05:00:12

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

  1. 格式化整个代码(整个类/控制器)

    选择整个代码,然后在 Mac 上按 control+I 格式化代码。

  2. 格式化特定代码块

    选择代码并按:

    • +] 向右移动(缩进)
    • +[ 向左移动(不缩进)

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

  1. 选择您的代码并导航到编辑器>; 结构> 重新缩进

Here are the shortcuts, to format the code in XCode

  1. Format entire code (entire class/controller)

    Select the entire code and press control+I on mac to format your code.

  2. Format particular block of code

    Select the code and press:

    • +] for right move (indent)
    • +[ for left move (un-indent)

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

  1. Select your code and navigate to Editor > Structure > Re-Indent
时光匆匆的小流年 2024-07-26 05:00:12

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

其次,按住 ctr 键,然后按 i

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

First, select all code using command+a

Second, hold key ctr and then press i

the whole selected code will nicely indent.

呆° 2024-07-26 05:00:12

多行缩进 快捷键:

ctrl + i

注意:请选择要重新缩进的代码,然后在 Mac 上按“control”和“i”。

Multiline Indentation Shortcut key:

ctrl + i

NOTE: Please select codes to Re-indent and press 'control' and 'i' on your mac.

宁愿没拥抱 2024-07-26 05:00:12

快速重新格式化缩进的另一种方法是快速剪切和粘贴。 +x+v。 我经常发现它比 +[+] 更快,因为你可以用一只手完成(与两个),它将一次性重新格式化为正确的缩进级别。

Another way to quickly reformat indenting is a quick cut and paste. +x and +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.

淡墨 2024-07-26 05:00:12

如果你使用synergy(两台电脑共用一个键盘),并且你使用xcode的电脑(MAC)是从机,主控电脑是Windows电脑,

键盘快捷键是alt+]< /kbd> 用于缩进,alt+[ 用于取消缩进。

更新:

但是从synergy版本1.5开始,+[用于缩进,+] 用于取消缩进

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

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

Update:

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

佞臣 2024-07-26 05:00:12

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

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

我不吻晚风 2024-07-26 05:00:12

在“首选项”->“文本编辑”->“缩进”中选择“Tab 键:始终缩进”
然后,您可以通过按 TABSHIFT+TAB 缩进单行或选定的行
遗憾的是,这完全消除了在您想要的位置插入选项卡的可能性,并且与用于在“自动完成字段”之间切换的选项卡键严重冲突。

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

Select "Tab key: Indents always" in Preferences->Text Editing->Indentation
Then you can indent a single line or a selection of lines by pressing TAB or SHIFT+TAB
Sadly 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".

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

俯瞰星空 2024-07-26 05:00:12

对于代码缩进,首先选择代码行,然后按:

command + alt + [

command + alt + ]

For code indentation first select the lines of code then press:

command + alt + [

command + alt + ]

三人与歌 2024-07-26 05:00:12

选择行并按键盘上的 Ctrl+i

您将缩进这些行。

Select the lines and press Ctrl+i from keyboard.

You will have the lines indented.

讽刺将军 2024-07-26 05:00:12

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

缩进选择:

+ + + )

取消缩进选择:

+ + + (

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

Indent selection:

+ + + )

Unindent selection:

+ + + (

避讳 2024-07-26 05:00:12

对于那些在 Mac 上使用西班牙语键盘的人,这些快捷键是:

+ + [缩进

+ + ] 进行缩进

For those of you with Spanish keyboard on mac this are the shortcuts:

+ + [ for un-indent

+ + ] for indent

孤独难免 2024-07-26 05:00:12

这里是堆栈溢出上回答的另一个问题的所有重要快捷方式
此处

here all the important shortcuts from another question answered on stack overflow
here

秉烛思 2024-07-26 05:00:12

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

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

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

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

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

      
      <根> 
          <项目> 
              Tab 代替 Command+[ 
              <标识符>private.swap_tab_and_cmnd+[ 
              <自生体> 
                  __键对键__ 
                  键码::TAB, ModifierFlag::NONE, 
                  KeyCode::BRACKET_RIGHT,ModifierFlag::COMMAND_L |   修饰符标志::无 
               
            
       
      
  5. 转到首选项 ~> “更改密钥”~> 单击“重新加载 XML”按钮

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

  7. 享受

在此处输入图像描述

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

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

  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

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.

红衣飘飘貌似仙 2024-07-26 05:00:12

丹麦语键盘

取消缩进: + + 8

缩进: + + 9

Danish Keyboard

Unindent: + + 8

Indent: + + 9

爱格式化 2024-07-26 05:00:12

基本上 [ 表示左多重缩进, ] 右多重缩进。

对于 TR 键盘,您可以使用 8 进行左多重缩进,使用 ⌘< 进行右多重缩进。 /kbd> 9。因为 89 都是 ALT 字符这些数字。或者,如果您的键盘上有 [] 字符,则属于 ALT( ) 属性,以便您可以使用 键盘字符

Basically [ for left multiple indent and ] right multiple indent.

For TR keyboard you can left multiple indent with 8 and right multiple indent with 9.Because both 8 and 9 are ALT characters of the these nums.Or if you have a keyboard which has [ or ] characters are belong to ALT() property so you can use KEYBOARD CHARACTER

尬尬 2024-07-26 05:00:12

由于我没有看到当前版本的 Xcode 对此问题的更新,我想我应该在 Xcode 9.3 中添加这一点,Tab 可用于缩进选定的文本行以及从一个自动完成字段移动到另一个自动完成字段。

Since I didn't see an update to this question for the current version of Xcode, I thought I'd add that in Xcode 9.3, Tab works for indenting selected line(s) of text as well as moving from one autocomplete field to another.

多情癖 2024-07-26 05:00:12

在 Xcode 4.2 中,自动缩进非常好。 现在,您可以通过按 Tab 键缩进选定的代码。 我发现 Xcode 通常可以很好地自动格式化代码,并且您很少需要自己移动东西。 我发现选择一段代码,右键单击并选择“结构”->“结构”会更快。 如果某些代码看起来很混乱,请重新缩进。

In Xcode 4.2 auto-indenting is pretty good. You can now indent a selection of code by pressing the Tab key. I find that Xcode generally formats code really well automatically, and you rarely have to move things around yourself. I find it faster to select a piece of code, right-click and choose Structure -> Re-indent if some code looks messy.

只有一腔孤勇 2024-07-26 05:00:12

缩进选项卡
SHIFT + Tab 重新缩进

Tab for Indent
SHIFT + Tab Re-indent

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文