💾 Archived View for pwshnotes.flounder.online › gemlog › 2022-08-15-formatting-vim.gmi captured on 2024-02-05 at 09:35:15. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Formatting Plain Text Copies in Vim

I prefer to read long passages in Vim. So, I copy and paste from the Web into Vim.

Sometimes, the plain text copy of an online document is difficult to read in Vim.

Below are some advanced Vim commands to address specific issues.

If you get unexpected results from running multiple commands, try running the commands in the order they appear here.

In Vim, you can paste at the command line by pressing Ctrl-r and then + So, it is possible to copy and paste these commands without typing. Take care to include only one leading colon : in your commands.

Separate Headings

:%s/\S\n\zs\(\S\)/\r\1

Here, \r will add a carriage return to the output.

The above Vim command will add a blank line before headings.

We go from this:

... and terminal.integrated.tabs.defaultColor.
Extended PowerShell keybindings

to this:

... and terminal.integrated.tabs.defaultColor.

Extended PowerShell keybindings

Add Line Breaks to Paragraphs

:g/^\w.\{79,}\|^    \w.\{75,}\|^        \w.\{71,}/normal gqgq

The Vim command above will add line breaks to long paragraphs. I find this helps if, later, I use a linewise visual select while reading.

Turn this paragraph with no line breaks:

There are additional PowerShell keybindings, such as Ctrl+Space, thanks to shell integration. These weren't possible before due to the lack of VT encoding. Provided that shell integration is working in pwsh, the following keybindings should now work:

into this paragraph with a line break at the end of each line:

There are additional PowerShell keybindings, such as Ctrl+Space, thanks to
shell integration. These weren't possible before due to the lack of VT
encoding. Provided that shell integration is working in pwsh, the following
keybindings should now work:

References

Example Source Document

Basic Information About Vim Modes (e.g. Normal Mode)

Introduction to the Vim Command Line

Command Line Reference

Manual Page for Regular Expressions in Vim

The meaning of % in :%s/ | Vim Range

:s Command

:g Command

:normal | Using Normal Mode Commands in Command-line Mode

gq Command in Normal Mode

Ctrl-r in Command-line Mode

Vim Registers (Clipboards)

Selecting Lines | Linewise Visual Select | Vim User Manual

Created: Monday, August 15, 2022

Updated: Saturday, October 8, 2022