Xcode source automatic formatting

后端 未结 19 627
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 16:10

As a C# developer, I have become highly dependent on the automatic formatting in Visual Studio 2008. Specifically, I will use the CTRL + K , D

相关标签:
19条回答
  • 2020-11-29 16:38

    This only works for languages with are not whitespace delineated, but my solution is to remove all whitespace except for spaces, then add a newline after characters that usually delineate EOL (e.g. replace ';' with ';\n') then do the ubiquitous ^+i solution.

    I use Python.

    Example code, just replace the filenames:

    python -c "import re; open(outfile,'w').write(re.sub('[\t\n\r]','',open(infile).read()).replace(';',';\n').replace('{','{\n').replace('}','}\n'))"
    

    It 's not perfect (Example: for loops), but I like it.

    0 讨论(0)
  • 2020-11-29 16:39

    In xcode, you can use this shortcut to Re-indent your source code

    Go to file, which has indent issues, and follow this :

    • Cmd + A to select all source codes

    • Ctrl + I to re-indent

    Hope this helps.

    0 讨论(0)
  • 2020-11-29 16:39

    Swift - https://github.com/nicklockwood/SwiftFormat

    It provides Xcode Extension as well as CLI option.

    0 讨论(0)
  • 2020-11-29 16:40

    CTRL + i

    that's it.

    (no COMMAND + i)

    0 讨论(0)
  • 2020-11-29 16:42

    You can also have a look at https://github.com/octo-online/Xcode-formatter which is a formatter based on Uncrustify and integrated into Xcode. Works like a charm.

    0 讨论(0)
  • 2020-11-29 16:45

    You can use Command + A to select all content and next Ctrl + I to format the selected content.

    0 讨论(0)
提交回复
热议问题