Sublime Text has options trim_trailing_white_space_on_save
and ensure_newline_at_eof_on_save
to handle whitespace.
In some situations, these options do not give satisfactory result. While similar packages exist, e.g., TrailSpaces, they do not allow easier syntax specific settings.
Whitespace helps in keeping your code clean by providing more features in removing trailing spaces.
- remove trailing whitespace
- ensure single trailing newline
- ignore whitespace only lines
- ignore whitespace on current line
- Download & Install
Sublime Text 3
(https://www.sublimetext.com/3) - Go to the menu
Tools -> Install Package Control
, then, wait few seconds until the installation finishes up - Now,
Go to the menu
Preferences -> Package Control
- Type
Add Channel
on the opened quick panel and press Enter - Then,
input the following address and press Enter
https://raw.githubusercontent.com/evandrocoan/StudioChannel/master/channel.json
- Go to the menu
Tools -> Command Palette... (Ctrl+Shift+P)
- Type
Preferences: Package Control Settings โ User
on the opened quick panel and press Enter - Then,
find the following setting on your
Package Control.sublime-settings
file:"channels": [ "https://packagecontrol.io/channel_v3.json", "https://raw.githubusercontent.com/evandrocoan/StudioChannel/master/channel.json", ],
- And,
change it to the following, i.e.,
put the
https://raw.githubusercontent...
line as first:"channels": [ "https://raw.githubusercontent.com/evandrocoan/StudioChannel/master/channel.json", "https://packagecontrol.io/channel_v3.json", ],
- The
https://raw.githubusercontent...
line must to be added before thehttps://packagecontrol.io...
one, otherwise, you will not install this forked version of the package, but the original available on the Package Control default channelhttps://packagecontrol.io...
- The
- Now,
go to the menu
Preferences -> Package Control
- Type
Install Package
on the opened quick panel and press Enter - Then,
search for
Whitespace
and press Enter
See also:
- ITE - Integrated Toolset Environment
- Package control docs for details.
-
The easiest way to apply "remove trailing whitespace" is by Command Palette
C+Shift+P
. -
To activate "remove trailing whitespace on save", click the menu items in
Edit -> Whitespace
. -
To enable Whitespace at startup, modify your preference setting file. If you want to enable Whitespace for a specific syntax, edit
Preferences -> Settings - More -> Syntax Specific
:
{
"remove_trailing_whitespace_on_save": true,
"ensure_single_trailing_newline": true,
"ignore_whitespace_only_lines": false,
"ignore_whitespace_on_current_line": true
}
The options explain themselves. Their default values are false
. You can also make use of Syntax Manager to enable Whitespace for multiple syntaxes.