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 - [ViEmu: Graphical vi cheatsheet](http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html)
11 #### Yank / delete an arbitrary number of lines
13 1) mark the first line: mk
14 2) move to last line
15 3a) yank: y'k
16 3b) delete: d'k
17 4) move to new line
18 5) paste with P or p
20 #### Apply regex to an arbitrary number of lines
22 1) mark the first line: mk
23 2) mark the last line: ml
24 :'k,'ls/regex/power/g
26 #### Add # to block of text
28 :'k,'ls/.*/#&/
30 #### Remove trailing whitespace of block of text
32 :'k,'ls/\ *$//
34 #### Write file as root
36 :w !doas tee %
38 #### Diff the file on disk with the file in the buffer
40 :w !diff -u % -
42 #### Make a backup of the file on disk
44 :!cp % %.bak
46 #### Sort all lines
48 :%!sort
50 #### Sort paragraph
52 !}sort
54 #### Uniq all lines
56 :%!uniq
58 #### Uniq paragraph
60 !}uniq
62 #### Join all lines
64 :%j
66 #### Select a column (3rd) from formated text seperated by ':'
68 :%!awk -F':' '{print $3}'