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




/gemlog/