xcode 默认启用代码折叠
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2364484/
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
Enable code-folding by default
提问by Infinite
Is there a way to tell XCode fold methods/functions by default when opening a file?
打开文件时,有没有办法在默认情况下告诉 XCode 折叠方法/函数?
回答by Kristian
Not sure if this is an OS change, or an Xcode change, but on Lion with Xcode 4, some of these commands cited by Griffo are performed with the Option modifier (the ? key), not control. I've made some changes to reflect this:
不确定这是操作系统更改还是 Xcode 更改,但在带有 Xcode 4 的 Lion 上,Griffo 引用的其中一些命令是使用 Option 修饰符(? 键)执行的,而不是控制。我进行了一些更改以反映这一点:
Fold? ? ? ? ? ? ? ? ? ? ? ???← ? ? ?option+command+left
Unfold ? ? ? ? ? ? ? ? ? ? ???→ ? ? ?option+command+right
Unfold All ? ? ? ? ? ? ? ? ??U ? ? ? ?option+U
Fold Methods/Functions ? ? ???↑ ? ? ?option+command+up
Unfold Methods/Functions ? ???↓ ? ? ?option+command+down
Sorry to necro a thread, but I thought this was worthwhile to revise.
对不起,我死了一个线程,但我认为这是值得修改的。
回答by Custom Bonbons
If you want to fold / unfold specific blocks of code, since Xcode 7, you have to enable that.
如果你想折叠/展开特定的代码块,从 Xcode 7 开始,你必须启用它。
Go to Xcode > Preferences > Text Editing > and check 'Code folding ribbon'.
转到 Xcode > Preferences > Text Editing > 并选中“代码折叠功能区”。
(No idea why they disabled this useful feature by default.)
(不知道为什么他们默认禁用了这个有用的功能。)
回答by Krunal
Updates in Xcode 10:
Xcode 10 中的更新:
Xcode 10 has increased support for code folding, including:
Xcode 10 增加了对代码折叠的支持,包括:
- A new code folding ribbon showing all of the multi-line foldable blocks of code in the editor
- A new style for folded code in the editor that allows you to edit lines with folded code
- Support for folding any block of code enclosed in curly braces
- Support for folding blocks of code from the folding ribbon, from structured selection, or from the
- 显示编辑器中所有多行可折叠代码块的新代码折叠功能区
- 编辑器中折叠代码的新样式,允许您编辑带有折叠代码的行
- 支持折叠花括号中的任何代码块
- 支持从折叠功能区、结构化选择或从
Menubar ? Editor ? Code Folding ? Fold menu item
菜单栏 ?编辑?代码折叠 ? 折叠菜单项
Look at this snapshot:
看看这个快照:
Code folding was disabled in Xcode 9 beta 1, which is working now, in Xcode 9 Beta5 according to beta release note: Resolved in Xcode 9 beta 5 – IDE
代码折叠在 Xcode 9 beta 1 中被禁用,它现在正在运行,在 Xcode 9 Beta5 中根据测试版发布说明:在 Xcode 9 beta 5 – IDE 中解决
Here is how:
方法如下:
- Press and hold
?
(command) button in keyboard and move/hover mouse cursor on any (start or end) braces. It will automatically highlight, block area. - Keep (hold)
?
(command) button in pressed condition and click on highlighted area. It will enable quick menu popover window withFold
option. - Select
Fold
from menu list. It will fold your code and shows 3 dots, folding/covering entire block. - Now, to again unfold your code block, release
?
(command) button and click on 3 dots folding a block.
- 按住
?
键盘上的(命令)按钮并将鼠标光标移动/悬停在任何(开始或结束)大括号上。它会自动突出显示,阻止区域。 - 保持(按住)
?
(命令)按钮处于按下状态,然后单击突出显示的区域。它将启用带有Fold
选项的快速菜单弹出窗口。 Fold
从菜单列表中选择。它将折叠您的代码并显示 3 个点,折叠/覆盖整个块。- 现在,再次展开您的代码块,释放
?
(命令)按钮并单击折叠块的 3 个点。
For easy understanding, look at this snapshot:
为了便于理解,请看这张快照:
It's all keyboard short cuts are also working.
所有的键盘快捷键也都有效。
Fold ? ? ← option + command + left arrow
Unfold ? ? → option + command + right arrow
Unfold All ? U option + U
Fold Methods & Functions ? ? ↑ option + command + up arrow
Unfold Methods & Functions ? ? ↓ option + command + down arrow
Fold Comment Blocks ? ? ? ↑ control + shift + command + up
Unfold Comment Blocks ? ? ? ↓ control + shift + command + down
Focus Follows Selection ? ? ? F control + option + command + F
Fold All ? ? ? ← command + option + shift + left
Unfold All ? ? ? → command + option + shift + left
Code folding options from Xcode Menu:
Xcode Menu 中的代码折叠选项:
Menubar ? Editor ? Code Folding ? "Here is list of code folding options"
菜单栏 ?编辑?代码折叠 ? “这是代码折叠选项列表”
Here is ref snapshot:
这是参考快照:
Same options from Xcode Short-cut list:
来自 Xcode Short-cut list 的相同选项:
Menubar ? Xcode ? Preferences ? Key Bindings ? "Here is list of code folding short-keys"
菜单栏 ?代码?喜好 ?键绑定?“这是代码折叠快捷键列表”
回答by Greg
The correct answer is in some of the comments (not in any of the answers, I don't think...
正确答案在一些评论中(不在任何答案中,我不认为......
incidentally, the shortcut keys for this are here:
顺便说一下,这里的快捷键在这里:
Judging from past answers, this must have changed over time. This is from Xcode 6.1.1.
从过去的答案来看,这一定会随着时间的推移而改变。这是来自 Xcode 6.1.1。
回答by Ali
For the sake of completeness,
为了完整起见,
Fold All ???← command+option+shift+left
回答by conorgriffin
I don't think so, there are some handy keyboard shortcuts though:
我不这么认为,不过有一些方便的键盘快捷键:
Fold ??← control+command+left
Fold All ???← command+option+shift+left
Unfold ??→ control+command+right
Unfold All ?U control+U
Fold Methods/Functions ??↑ control+command+up
Unfold Methods/Functions ??↓ control+command+down
Fold Comment Blocks ???↑ control+shift+command+up
Unfold Comment Blocks ???↓ control+shift+command+down
Focus Follows Selection ???F control+option+command+F
回答by geekinit
I feel your pain. It is difficult to press cmd+option+shift+left every time I open an implementation file to collapse all the methods. I would be grateful to know of a way to set this by default. On the other hand, a probably obvious workaround may be to select the method from the method picker at the top of the window. I suppose this is how the Xcode developers intended us to find methods.. still cmd+option+shift+left is my preference.. it just hurts my hand :/
我感觉到你的痛苦。每次打开一个实现文件都很难按cmd+option+shift+left来折叠所有方法。我很高兴知道默认情况下设置它的方法。另一方面,一个可能明显的解决方法可能是从窗口顶部的方法选择器中选择方法。我想这就是 Xcode 开发人员希望我们找到方法的方式.. 仍然 cmd+option+shift+left 是我的偏好..它只是伤害了我的手:/