Trim Whitespace
Trim Whitespace trims unnecessary blank characters from your Obsidian documents. This is a common feature in code editing software, and mostly exists to pare down irksome document clutter.
Features
The plugin operates on three different types of whitespace, with three different targets.
Whitespace Types
- Spaces - The space character, (
·
) - Tabs - The tab character, (
\t
or→
) - Lines - Newline character, either, (
\r
or\n
, stylised as¬
)
Targets
Trailing
Trim whitespace at the end of each line, or open document.
Before | After |
---|---|
Hello·World!···· |
Hello·World! |
Hello·World!→→→ |
Hello·World! |
# Hello¬ |
# Hello¬ |
Leading
Trim whitespace at the start of each line, or open document.
Before | After |
---|---|
····Hello·World! |
Hello·World! |
→→→Hello·World! |
Hello·World! |
¬ |
# Hello¬ |
Multiple
Trim groups of whitespace (2 or more consecutive inline spaces/tabs, or consecutive lines)
Before | After |
---|---|
Hello···World! |
Hello·World! |
Hello→→→World! |
Hello→World! |
# Hello¬ |
# Hello¬ |
Commands
- Trim whitespace in document trims all whitespace in the active document, according to the settings below
- Trim whitespace in selection trims all whitespace in the selected region in the active document, according to the settings below
Trim Whitespace also adds a ribbon button to trim document whitespace. Hold shift when clicking the button to trim whitespace in selection instead.
Settings
Name | Description |
---|---|
Auto-Trim | Automatically trim document when modified, according to the settings below. |
Auto-Trim Delay | Time to wait in seconds before auto-trimming. |
Skip Code Blocks | Whether to ignore code blocks when trimming. |
Trim Trailing Spaces | Trim spaces at the end of each line. |
Trim Trailing Tabs | Trim tabs at the end of each line. |
Trim Trailing Lines | Trim empty lines at the end of the document. |
Trim Leading Spaces | Trim spaces at the start of each line. |
Trim Leading Tabs | Trim tabs at the start of each line. |
Trim Leading Lines | Trim lines at the start of the document. |
Trim Multiple Spaces | Trim groups of multiple inline spaces. |
Trim Multiple Tabs | Trim groups of multiple inline tabs. |
Trim Multiple Lines | Trim groups of multiple blank lines. |
Installation
To install, either:
- Install manually with the zip in Releases, or (hopefully eventually)
Download from the Obsidian Community Plugin library
Known Bugs
- Trimming the whole document doesn't reset cursor position properly, if the original location started before the first non-space character in the document.
Credit Due
- Community interest sparked by this forum post
- Plugin basics grokked from @Benature's obsidian-text-format
- Lots of support from the Obsidian Community Discord server