1 d739a660 2019-04-06 git # Why vi Rocks
3 18871106 2019-04-06 git A collection of commands, command sequences in [vi(1)](https://man.openbsd.org/vi.1)/[ex(1)](https://man.openbsd.org/ex.1) or with 3rd party unitilities.<br />
4 18871106 2019-04-06 git These all work with at least [nvi](https://en.wikipedia.org/wiki/Nvi) 1.79 and 2.1.3 (unicode).
6 7d2c94db 2019-04-06 git Helpful documents:<br />
7 7d2c94db 2019-04-06 git - [Roman Zolotarev: Edit text with vi(1)](https://rgz.ee/vi.html)<br />
8 af599e02 2019-04-06 git - [Jeff W: vi help](http://www.jeffw.com/vi/vi_help.txt)<br />
9 ee9f7a40 2019-04-07 git - [Maarten Litmaath: vi reference](http://www.ungerhu.com/jxh/vi.html)<br />
10 ee9f7a40 2019-04-07 git - [alphanrrrd: extremely concise cheatsheet](http://www.alphanrrrd.org/vi.html)<br />
11 af599e02 2019-04-06 git - [ViEmu: Graphical vi cheatsheet](http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html)
13 6c9b71bc 2019-04-06 git #### Yank / delete an arbitrary number of lines
15 18871106 2019-04-06 git 1) mark the first line: mk
16 18871106 2019-04-06 git 2) move to last line
17 18871106 2019-04-06 git 3a) yank: y'k
18 18871106 2019-04-06 git 3b) delete: d'k
19 18871106 2019-04-06 git 4) move to new line
20 18871106 2019-04-06 git 5) paste with P or p
22 6c9b71bc 2019-04-06 git #### Apply regex to an arbitrary number of lines
24 6c9b71bc 2019-04-06 git 1) mark the first line: mk
25 6c9b71bc 2019-04-06 git 2) mark the last line: ml
26 6c9b71bc 2019-04-06 git :'k,'ls/regex/power/g
28 66a0e66d 2019-04-06 git #### Add # to block of text
30 66a0e66d 2019-04-06 git :'k,'ls/.*/#&/
32 66a0e66d 2019-04-06 git #### Remove trailing whitespace of block of text
34 66a0e66d 2019-04-06 git :'k,'ls/\ *$//
36 6c9b71bc 2019-04-06 git #### Write file as root
38 18871106 2019-04-06 git :w !doas tee %
40 ee594e64 2019-04-06 git #### Diff the file on disk with the file in the buffer
42 18871106 2019-04-06 git :w !diff -u % -
44 18871106 2019-04-06 git #### Make a backup of the file on disk
48 6c9b71bc 2019-04-06 git #### Sort all lines
52 6c9b71bc 2019-04-06 git #### Sort paragraph
56 6c9b71bc 2019-04-06 git #### Uniq all lines
60 6c9b71bc 2019-04-06 git #### Uniq paragraph
64 6c9b71bc 2019-04-06 git #### Join all lines
68 6c9b71bc 2019-04-06 git #### Select a column (3rd) from formated text seperated by ':'
70 6c9b71bc 2019-04-06 git :%!awk -F':' '{print $3}'