From d904acc931e118a3cd7b7ba65c48224f295874e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 19 Jun 2021 11:28:32 +0200 Subject: Add README --- README | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..5ad7225 --- /dev/null +++ b/README @@ -0,0 +1,46 @@ +vp is a powerful UNIX tool for interactively building shell commands. +For more information, read the vp.1 manual. + +Below are some examples of how I've successfully used vp to perform +advanced ad-hoc text processing in my everyday life. + += Sort paragraphs alphabetically = + +I once found myself wanting to sort function definitions alphabetically. +Luckily, the solution was simplified by the fact that functions +didn't contain any blank lines. Here's how I did it. + + 1. Open the file in vi. + + 2. Cut the function definitions to the clipboard: + + !xsel -i + + 3. Launch vp: + + :!vp + + 4. Write something along the following lines: + + xsel -o | perl -00 -ne ' + push @d, $_; + END { print for sort @d }' + + 5. When you've found a command that works, press q to keep + the output. + + 6. Copy the buffer: + + :%!xsel -i + + 7. Quit vp, return to the original vi session and paste the + sorted function definitions. + +For a more general solution, which supports blank lines within +definitions, I came up with the following command: + + xsel -o | perl -ne ' + @d[$i] .= $_; + $i++ if /^}/; + END { print for sort @d } + ' -- cgit v1.2.3