Trim Whitespace

approved

by Zack Lovatt

Trim unnecessary whitespace.

61 stars14,150 downloadsUpdated 4mo agoMIT
View on GitHub

Trim Whitespace

Obsidian Downloads GitHub stars

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

  1. Spaces - The space character, ( , stylised as ·)
  2. Tabs - The tab character, (\t or , stylised as )
  3. Lines - Newline character, either, (\r or \n, stylised as ¬)

Targets

Trailing

Trim whitespace at the end of each line, or open document.

BeforeAfter
Hello·World!····
Hello·World!
Hello·World!→→→
Hello·World!
# Hello¬
¬
World!¬
¬
¬
# Hello¬
¬
World!¬

Leading

Trim whitespace at the start of each line, or open document.

BeforeAfter
····Hello·World!
Hello·World!
→→→Hello·World!
Hello·World!
¬
¬
# Hello¬
¬
World!¬
# Hello¬
¬
World!¬

Multiple

Trim groups of whitespace (2 or more consecutive inline spaces/tabs, or consecutive lines)

BeforeAfter
Hello···World!
Hello·World!
Hello→→→World!
Hello→World!
# Hello¬
¬
¬
World!¬
¬
¬
# Hello¬
¬
World!¬

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

NameDescription
Trim on Manual SaveManually trim document with CTRL / CMD + S
Auto-TrimAutomatically trim document when modified, according to the settings below.
Auto-Trim DelayTime to wait in seconds before auto-trimming.
Preserve Code BlocksWhether to preserve whitespace within code blocks.
Trim Trailing SpacesTrim spaces at the end of each line.
Trim Trailing TabsTrim tabs at the end of each line.
Trim Trailing LinesTrim empty lines at the end of the document.
Preserve Indented ListsWhether to preserve whitespace if used for list indentation.
Trim Leading SpacesTrim spaces at the start of each line.
Trim Leading TabsTrim tabs at the start of each line.
Trim Leading LinesTrim lines at the start of the document.
Trim Multiple SpacesTrim groups of multiple inline spaces.
Trim Multiple TabsTrim groups of multiple inline tabs.
Trim Multiple LinesTrim groups of multiple blank lines.

Installation

To install, either:

  1. Download from the Obsidian Community Plugin library, or
  2. Install manually with the zip in Releases

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.

Contribution

Want to help develop or maintain this plugin? Please do! PRs and input extremely welcome!


Credit Due

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.