Remove All Blank Lines In File

Basic editor question
How can I remove all blank lines in a file?

I’m not aware of a way to do that with Obsidian’s editor unless you are using Vim mode. The built-in search/replace command only supports basic string matching as far as I know. But there are options.

Many people use an external editor like VS Code, Sublime text, or CLI tools to make bulk edits to docs in their vaults. Those options have more complete find/ replace tools. The notes are just files after all.

If you are familiar with vim, you can enable that in Settings > Editor > Vim key bindings and replace all blank lines in the current file with this ex command. I’m sure there’s a way to do this with templater too

:%s/^$\n*//g

That

  1. substitutes: %s
  2. empty lines and the carriage return characters immediately after: /^$\n*/
  3. with nothing: //
  4. everywhere in the file: g

or if you are on windows, likely need

:%s/^$(\r\n)*//g
1 Like

Thanks Paul!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.