Trailing SpacesA VS Code extension that allows you to… highlight trailing spaces and delete them in a flash! This extension is a port of the popular Sublime Text plugin Trailing Spaces. SynopsisVS Code provides a way to automate deletion of trailing spaces by using the Trim Trailing Whitespace command. Depending on your settings, it may be more handy to just highlight them and/or delete them by hand, at any time. This plugin provides just that, and a lot of options to fine-tune the way you want to decimate trailing spaces. InstallationIt is available through Visual Studio Marketplace and this is the recommended way of installation (brings integrated updates). UsageDeleteThe main feature you gain from using this plugin is that of deleting all trailing spaces in the currently edited document. In order to use this deletion feature, you may either:
To add a key binding, open "File / Preferences / Keyboard Shortcuts" and add:
With this setting, pressing Alt + Shift + t will delete all trailing spaces at once in the current file! Delete - Modified Lines OnlyYou can also delete the trailing spaces exclusively from the modified (unsaved) lines. In order to use this deletion feature, you may either:
To add a key binding, open "File / Preferences / Keyboard Shortcuts" and add:
HighlightAt any time, you can highlight the trailing spaces. You may either:
OptionsSeveral options are available to customize the plugin's behavior. Those settings are stored in a configuration file, as JSON. You must use a specific file: Go to "File / Preferences / User Settings" to add your custom settings. All settings are global (ie. applied to all opened documents). Highlight Current LineDefault: true Highlighting of trailing spaces in the currently edited line can be annoying: each time you are about to start a new word, the space you type is matched as a trailing spaces. Currently edited line can thus be ignored:
Even though the trailing spaces are not highlighted on this line, they are still internally matched and will be deleted when firing the deletion command. If you are editing multiple lines (using multiple cursors), all such lines will be ignored. Include Empty LinesDefault: true When firing the deletion command, empty lines are matched as trailing regions, and end up being deleted. You can specifically ignore them:
They will not be highlighted either. Note: This option only deletes the trailing spaces in blank lines and not the whole line itself. If you want to delete the newline character as well, please consider changing the regex. Delete Modified Lines OnlyDefault: false When firing the deletion command, trailing regions in the entire document are deleted. There are some use-cases when deleting trailing spaces only on lines you edited is smarter; for instance when commiting changes to some third-party source code. At any time, you can change which area is covered when deleting trailing regions by changing the setting:
Trim On SaveDefault: false Setting this to
~~Save After Trim~~ [REMOVED]NOTE: The current VSCode lifecycle for text editor commands does not provide a clean way to implement this feature. Since I did not see a lot of folks using this option, it was better to remove it. Default: false You may not want to always trim trailing spaces on save, but the other way around could prove useful. Setting this to
It is obviously ignored if Trim On Save is on. Live Matching vs On-demand MatchingDefault: true (reload VS Code Window to update) By default, trailing regions are matched every time you edit the document, and when you open it. This feature is entirely optional and you may set it off: firing the deletion command will cause the trailing spaces to be deleted as expected even though they were not matched prior to your request. If you are afraid of the plugin to cause slowness (for instance, you already installed several heavy extensions), you can disable live matching:
In this case, for no trailing regions are matched until you request them to be deleted, no highlighting occurs—it is in fact disabled. If you want to check the trailing spaces regions, you can use the Ignore SyntaxDefault: [] With this option you can ignore specific files based on the language used. An item has to match the case-sensitive string of the language used in the file:
Here is a list of all languages that VS Code supports (as of 28 March 2019):
For the most recent list of langauges, please use the known language identifiers page or the Ignore SchemeDefault: ["output"] With this option you can ignore documents with a specific scheme. An item has to match the case-sensitive string of the scheme of the document. For instance, if you want to ignore VSCode output windows:
Show Status Bar MessageDefault: true By default, trailing space deletions will be communicated through a status bar message. Set this to
Background ColorDefault: rgba(255,0,0,0.3) You can control the background color of the highlighting performed by Trailing Spaces using this option. To set up another color change the setting:
To make the highlighting invisible, set this and the border color properties to Border ColorDefault: rgba(255,100,100,0.15) You can control the border color of the highlighting performed by Trailing Spaces using this option. To set up another color change the setting:
To make the highlighting invisible, set this and the background color properties to For power-users only!The matching patternDefault: [ \t]+ Trailing spaces are line-ending regions containing at least one simple space, tabs, or both. This pattern should be all you ever need, but if you do want to abide by another definition to cover edge-cases, go ahead:
Contributions
|