Trims unnecessary whitespace from your Obsidian documents.

Overview

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

  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.

Before After
Hello·World!····
Hello·World!
Hello·World!→→→
Hello·World!
# Hello¬
¬
World!¬
¬
¬
# Hello¬
¬
World!¬

Leading

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

Before After
····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)

Before After
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

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:

  1. Install manually with the zip in Releases, or (hopefully eventually)
  2. 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

Comments
  • Remove whitespace replaces inline code with code block

    Remove whitespace replaces inline code with code block

    This plugin is great, but in one of my code notes it had messed up several parts. I have oversimplified the case to the bare minimum and share this reproducible version.

    A line with several inline codes
    
    `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`
    
    Two code blocks
    
    ```js
    console.log(1)
    ```
    
    ```js
    console.log(2)
    ```
    

    When I execute the command "Remove whitespace in document", I get this:

    A line with several inline codes
    
    `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, ```js
    console.log(2)
    ```0, `10`
    
    Two code blocks
    
    ```js
    console.log(1)
    ```
    
    TRIM_WHITESPACE_REPLACE_1
    

    The inline code `9` gets replaced with the second code block, and instead of the second code block now there is a placeholder TRIM_WHITESPACE_REPLACE_1

    The content of inline codes and code blocks do not change the result. It seems that the quantity and the position are what matters here. Adding more instances of inline code and code blocks, more of them get affected.

    The "Skip code blocks" option is enabled, in order to avoid changing indentation whitespace inside them.

    opened by andrezgz 3
  • Only the first code block is skipped

    Only the first code block is skipped

    I have each of the trimming rules enabled (for trailing, leading and multiple characters) and "Skip code blocks" option too. When I choose to "Remove whitespace in document", the first code block is skipped, but all of the subsequent ones get targeted by the rules and its whitespace is removed or turned into one (for a group of multiple inline spaces).

    The following is the minimum reproducible test case I could build:

    Identical code blocks
    
    ```js
    function log(text) {
        console.log   (`->  ${text}  <-`);  
        // the previous line has 2 trailing spaces
    }
    ```
    
    ```js
    function log(text) {
        console.log   (`->  ${text}  <-`);  
        // the previous line has 2 trailing spaces
    }
    ```
    

    When I execute the command "Remove whitespace in document", I get this:

    Identical code blocks
    
    ```js
    function log(text) {
        console.log   (`->  ${text}  <-`);  
        // the previous line has 2 trailing spaces
    }
    ```
    
    ```js
    function log(text) {
    console.log (`->  ${text}  <-`);
    // the previous line has 2 trailing spaces
    }
    ```
    

    For the console.log for the second code block note that leading and trailing whitespace was removed, and the 3 inline spaces were converted into a single one.

    The second code block should have been skipped as the first one.

    opened by andrezgz 1
  • trim happens too quickly

    trim happens too quickly

    Hi, thanks for going to the effort of creating this plugin.

    I have a slight issue, it trims when I pause typing, so that if I am not watching thenallmywords getjumbled. Could this plugin run on file save or after a configurable time period to prevent unwanted trimming?

    Many thanks once again kevin

    opened by 27escape 1
  • 'Multiple Characters' should skip within tables

    'Multiple Characters' should skip within tables

    When working with a table:

    | something   | else |
    | ----------- | ---- |
    | a           | b    |
    | a           | c    |
    

    This feature will strip formatting:

    | something   | else |
    | ----------- | ---- |
    | a | b |
    | a | c |
    

    While some markdown renderers display this properly, others don't (and viewing the raw file with the pretty table is now messed)

    opened by zlovatt 0
  • [Bug?] Turning off auto-trim should still trim on save

    [Bug?] Turning off auto-trim should still trim on save

    For reasons outlined in https://github.com/zlovatt/obsidian-trim-whitespace/issues/5, it's annoying to have auto-trim turned on. However, I still want to trim my document on save, i.e. when I press ctrl-s.

    When auto-trim is turned on, manually saving also trims whitespace from the document. However, when auto-trim is turned of, manually saving does not trim whitespace from the document. I'm not sure if this is intended, but my interpretation of auto-trim was that it would do it automatically when editing the document, whereas manually saving should always trim.

    My workaround is just to turn on auto-trim, but set the number of seconds to an absurdly high amount.

    opened by ZibingZhang 0
  • Suggestion: trigger when cursor leaves the current line

    Suggestion: trigger when cursor leaves the current line

    Hi there,

    Thanks for making this plugin!

    Obviously you'd know better than me– Do you think triggering when the cursor switches to a different line would feel more natural? Like how Obsidian switches from showing markdown characters in Live Preview mode.

    Just a thought. Cheers! Ryan

    opened by ryansalmond 0
  • Auto-trim should ignore whitespace adjacent to cursor

    Auto-trim should ignore whitespace adjacent to cursor

    If you're idling at the end of a line, thinking about what you want to type next, it's annoying when the plugin trims that intentional trailing space.

    Same deal if you've hit newline a few times and are about to type-- having it remove those is irksome.

    Suggested solve: ignore anything contiguous with the cursor.

    opened by zlovatt 1
Releases(0.2.2)
Owner
Zack Lovatt
2d Technical Director
Zack Lovatt
A plugin for the Obsidian markdown note application, adding functionality to render markdown documents with multiple columns of text.

Multi-Column Markdown Take your boring markdown document and add some columns to it! With Multi Column Markdown rather than limiting your document lay

Cameron Robinson 91 Jan 2, 2023
A plugin for Obsidian (https://obsidian.md) that adds a button to its search view for copying the Obsidian search URL.

Copy Search URL This plugin adds a button to Obsidian's search view. Clicking it will copy the Obsidian URL for the current search to the clipboard. T

Carlo Zottmann 6 Dec 26, 2022
Trim unnecessary indentation when pasting code

Unindent When pasting code from your editor into Discord, it often ends up having a lot of indentation. This plugin fixes that by trimming unnecessary

Vens Powercord Plugins 19 May 1, 2022
Remove unnecessary files from node_modules (.md, .ts, ...)

What? node-prune is a small tool to prune unnecessary files from ./node_modules, such as markdown, typescript source files, and so on. Primarily built

TJ Holowaychuk 4.3k Jan 1, 2023
Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed.

scrooth Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed. Why? I needed that, and I was unable to find p

Rafał Spiżewski 20 Aug 29, 2022
Obsidian Web: Connect your browser with your Obsidian notes

Obsidian Web: Connect your browser with your Obsidian notes This is an unofficial Chrome extension for Obsidian that lets you send content from the we

Adam Coddington 97 Jan 3, 2023
Codebraid Preview provides a Markdown preview for Pandoc documents within VS Code.

Codebraid Preview provides a Markdown preview for Pandoc documents within VS Code. Most Markdown previews don't support all of Pandoc's extensions to Markdown syntax. Codebraid Preview supports 100% of Pandoc features—because the preview is generated by Pandoc itself! There is also full bidirectional scroll sync and document export.

Geoffrey Poore 12 Dec 28, 2022
Apinto document project, which includes the use tutorials, development documents and other related contents of apinto.

apinto-docs Apinto document project, which includes the use tutorials, development documents and other related contents of apinto. README 本文档由 VuePres

Eolink 5 Dec 1, 2022
JSON Struct is a vocabulary that allows you to annotate and validate JSON documents.

JSON-Struct JSON Struct is a vocabulary that allows you to annotate and validate JSON documents. Examples Basic This is a simple example of vocabulary

Saman 3 May 8, 2022
A Hackable Markdown Note Application for Programmers. Version control, AI completion, mind map, documents encryption, code snippet running, integrated terminal, chart embedding, HTML applets, plug-in, and macro replacement.

Yank Note A hackable markdown note application for programmers Download | Try it Online >>> Not ecommended English | 中文说明 [toc]{level: [2]} Highlights

洋子 4.3k Dec 31, 2022
A Chinese unofficial documents site.

Grasscutter Documention | 割草机文档 This website is built using Docusaurus 2, a modern static website generator. 此网页使用Docusaurus 2创建,这是一个现代化网页生成器 English

GenKitCN 29 Dec 3, 2022
Add grouped tabsets, which remember the active tab across multiple HTML documents.

Grouped Tabsets See the extension in action. This quarto extension provides support for "grouped" tabsets in Quarto HTML documents. Consider the case

null 13 Sep 30, 2022
Digital Identifier is a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential identity-based documents to create a unique digital identity of a person.

Digital Identifier ?? To design and develop a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential ident

Mukul Kolpe 4 Dec 17, 2022
Identity APIs to used to generate DID documents for entities based on external identifiers.

Identity API This API is used to generate and decentralized identity documents for all entities that are stored in a registry. These documents contain

Verifiable Presentation Generation 5 Nov 24, 2022
An Obsidian plugin to paste Excel tables as Markdown tables in Obsidian editor.

Obsidian Excel to Markdown Table An Obsidian plugin to paste Excel tables as Markdown tables in Obsidian editor. Demo You can paste the copied Excel d

Ganessh Kumar 108 Jan 4, 2023
Obsidian-dataview-table-filter-menu - Dynamically created filter menu for dataview tables in obsidian

Dataview table Filter Menu for Obsidian Dynamically created filter menu for data

shiro 17 Sep 24, 2022
Obsidian-Snippet-collection - A collection of snippet to customize obsidian

This repo is a collection of CSS snippets for Obsidian.md. To install them on PC

Mara 110 Dec 22, 2022
This is a plugin for Obsidian (https://obsidian.md). Can open document with `.html` and `.htm` file extensions.

Obsidian HTML reader Plugin This is a plugin for Obsidian (https://obsidian.md). Can open document with .html and .htm file extensions. Obsidian HTML

null 37 Dec 27, 2022
An Obsidian plugin that lets you browse the web within Obsidian.

Obsidian Web Browser An Obsidian plugin that allows you to browse the web within Obsidian using v1.0 tabs. The core functionality of the plugin, rende

Dion Tryban 102 Dec 28, 2022