Trim trailing spaces in Xcode

后端 未结 7 2115

Is there a way to force Xcode to trim trailing whitespaces when I save file?

I\'m using version 3.1.3 if that matters.

7条回答
  •  遇见更好的自我
    2021-01-30 00:59

    You can create a script and bind it to a keyboard shortcut:

    • Select Scripts Menu > Edit User Scripts...
    • Press the + button and select New Shell Script
    • Give it a name like "Strip Trailing Spaces", and give it a shortcut like ⌃⇧R.
    • Set Input to "Selection" and Output to "Replace Selection"

    Then enter the following script:

    #!/usr/bin/perl
    
    while (<>) {
        s/\s+$//;
        print "$_\n";
    }
    

提交回复
热议问题