Blob


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