Textmate/Regex: Strip whitespace from beginning/end of file

前端 未结 3 748
梦毁少年i
梦毁少年i 2021-02-04 22:59

I\'m trying to add a macro/command to Textmate for some file cleanup and the last tidbit I haven\'t figured out is simply to remove blank lines from the beginning and end of a f

3条回答
  •  情深已故
    2021-02-04 23:12

    For the tasks you mentioned, you can use built-in commands from the "Text" Bundle.

    Even if you just want to script your own, i would suggest using these as templates for your own efforts.

    To access these:

    Removing Trailing Spaces:

    • ctrl-cmd-t to bring up the context-sensitive Bundle menu

    • begin typing "remove trailing", before you finish "remove", you should see the "Remove Trailing Spaces" Command move to the top of the menu (this Command is in the "Text" Bundle, one of the Bundles included with the TextMate )

    • "enter" will execute the command (assume the cursor is positioned correctly, etc.)

    Alternatively, you can access this Command using a key equivalent, but since one is not assigned in the default TextMate installation, you'll need to assign it yourself, which is simple to do:

    • ctrl-alt-cmd-b to bring up the Bundle Editor

    • find the Text Bundle then click on the "Remove Trailing Spaces" Command

    • In the upper right-hand-side of the Editor, toggle "Settings" and enter either a key equivalent or a "tab trigger" (which is activated by entering some key combination you assigned followed by the tab key.

    Remove Leading Spaces:

    This one's a macro rather than a command. It's probably easiest to access it via it's pre-configured key-equivalent, which is cmd-del

提交回复
热议问题