diff options
author | John Ankarström <john@ankarstrom.se> | 2021-06-19 11:28:32 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-06-19 11:28:32 +0200 |
commit | d904acc931e118a3cd7b7ba65c48224f295874e8 (patch) | |
tree | 19e846c0485ac224e42d307bc43fa19b3b333557 | |
parent | 8b50c699652e39812024af2c34973c6359302c46 (diff) | |
download | vp-d904acc931e118a3cd7b7ba65c48224f295874e8.tar.gz |
Add README
-rw-r--r-- | README | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -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 } + ' |