如何在 XCode 中快速删除 /* 和 */
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3732465/
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
How to delete /* and */ quickly in XCode
提问by node ninja
In XCode there are some useful functions commented out with /* and a corresponding */. Is there a shortcut that will quickly remove these? Can a shortcut be made using AppleScript, or is there a better way?
在 XCode 中有一些有用的函数用 /* 和相应的 */ 注释掉。有没有快捷方式可以快速删除这些?可以使用 AppleScript 制作快捷方式,还是有更好的方法?
回答by Brock Woolf
You can comment/uncomment any selected code block with Command+ /.
您可以使用Command+注释/取消注释任何选定的代码块/。
Press key combo again to toggle remove the comments from an already commented code block
再次按下组合键以切换从已注释的代码块中删除注释
In Xcode 4.2 I have to press Command+ Shift+/
在 Xcode 4.2 我必须按Command+ Shift+/
回答by Rob Napier
There's a better way to comment and uncomment code: Cmd+ /. It puts //
in front of every line, or removes //
if it's at the front of the line. This has many advantages. It's easier to do in Xcode. It nests correctly. It makes it very clear where commented out code is, even when read outside of an IDE (such as in diffs and code-review tools). It makes it much more obvious in diffs when a huge amount of code has just been committed (removing two lines makes it look like a little change, but you may have just injected hundreds of lines of untested-in-the-current-codebase code).
有一种更好的方式来注释和取消注释代码:Cmd+ /。它放在//
每一行的前面,或者//
如果它在行的前面则删除。这有很多优点。在 Xcode 中更容易做到。它嵌套正确。它非常清楚注释掉的代码在哪里,即使在 IDE 之外(例如在差异和代码工具中)也是如此。当刚刚提交了大量代码时,它在差异中变得更加明显(删除两行使它看起来像一个小改动,但您可能刚刚注入了数百行未经测试的当前代码库代码)。
If you're in a situation where you're hunting for a shortcut, then switching to leading //
is almost certainly a better solution.
如果您正在寻找捷径,那么切换到领导//
几乎肯定是更好的解决方案。