Saturday, August 22, 2015

Command to delete trailing white spaces in Sublime Text

After searching a while for how to replace trailing white spaces from the current document, I decided to go with my own method.

One simple way is to do regex replace.
ctrl+h
Find: [ \t]+$
Replace all [ctrl+alt+enter]

I wanted to do it via a keyboard shortcut. Here come "RegReplace" package to the rescue.

Hit ctrl+shift+p.
Install Package.
Search for "reg replace"
Install.

Now you can add new keybinding to you Keybindings-user file.
This is the keybinding.

{ "keys": ["ctrl+shift+t"], "command": "reg_replace",
        "args": {"replacements": ["remove_trailing_spaces"]}

}

Another  cool feature is that, we can just view the findings without replacing,
by setting "find_only": true.

{ "keys": ["ctrl+shift+t"], "command": "reg_replace",
        "args": {"replacements": ["remove_trailing_spaces"], "find_only": true}
 } 


After confirmation, you can press enter to replace all.

No comments:

Post a Comment