One of my favorite Vim tricks (which also works in vi) is the general technique of piping a specified range of text through a command (a Unix-style filter that reads from standard input and writes to standard output), with the output of that command then replacing that range of text.

The text can be anything from a single line, some arbitrary range of lines (defined via vim marks like a and b or other letters, some paragraphs (see example below), to the entire file - and the filter command can be anything at all, too. The Cartesian product of those two things makes it a very powerful technique.

An example is this key mapping of the character v to a command that format paragraphs of text using the fmt command [1]:

map v !}fmt -w 64<CR>

This says: map the letter v to the command following it (after the space), which is:

!}fmt -w 64<CR>

which runs/pipes (!) the current paragraph (when at top of a para, the cursor movement } defines a para) through the fmt -w 64 command, which formats its input text into lines of not more than 64 characters each.

(I just used v because it was one of the characters that Vim does not already assign a command to - any other available character will work.)

I have the mapping in my _vimrc on Windows and .vimrc on Unix.

With that mapping, I can reformat any paragraph (where paragraphs in vim are defined by a blank line either above and below them or both), just by going to the top of the paragraph (with { ) and typing v (no Enter needed).

For example, if I have this (single) line in a file in vim:

the quick brown fox jumped the quick brown fox jumped the quick brown fox jumped the quick brown fox jumped the quick brown fox jumped

and I press v when at the start of that line, it gets reformatted into this para:

the quick brown fox jumped the quick
brown fox jumped the quick brown fox
jumped the quick brown fox jumped the
quick brown fox jumped

I typically use this technique when writing text content (non-programming content, such as documentation, tech articles, blog posts, etc.) or sometimes even for block comments of text in programs.

You can also create a different version of that formatting command to filter the entire text file through fmt in one shot (that would be "!Gfmt -w 64" when at top of file, where G moves to the last line), but I tend not to use that approach much, because it sometimes messes up some paragraphs which should not be reformatted. So I do it a para at a time.

If you use the sort command instead of fmt, that will sort the range of lines you select, and the sorted lines replace the original lines. This is of course useful in text files and (text format) data files, but is also sometimes useful in source code, e.g. to sort lines of import statements (say in Python or Go - although Go has commands for that), ranges of variable declarations into alphabetical order, array literals, etc.).

[1] (Fmt is a Unix command, but you can probably get it in many of the Unix subsystems that run on Windows too, like Cygwin, UWin, Windows Subsystem for Linux too).
c
The command that you run the selected text through, can also be a Unix or Windows pipeline, which makes the technique even more powerful.