Blob


1 # Why vi Rocks
3 **[vi](https://en.wikipedia.org/wiki/Vi)** is the _de facto_ standard
4 Unix editor, you find it in every *NIX derived OS.
6 Here you will find a collection of commands, command sequences in
7 [vi(1)](https://man.openbsd.org/vi.1)/[ex(1)](https://man.openbsd.org/ex.1)
8 or with 3rd party unitilities which make
9 **[vi](https://en.wikipedia.org/wiki/Vi)** rock. These all work
10 with at least [nvi](https://en.wikipedia.org/wiki/Nvi) 1.79 and
11 2.1.3 (unicode).
13 Helpful documents:<br />
14 - [Roman Zolotarev: Edit text with vi(1)](https://rgz.ee/vi.html)<br />
15 - [Jeff W: vi help](http://www.jeffw.com/vi/vi_help.txt)<br />
16 - [Maarten Litmaath: vi reference](http://www.ungerhu.com/jxh/vi.html)<br />
17 - [alphanrrrd: extremely concise cheatsheet](http://www.alphanrrrd.org/vi.html)<br />
18 - [ViEmu: Graphical vi cheatsheet](http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html)
20 #### Yank / delete an arbitrary number of lines
22 1) mark the first line: mk
23 2) move to last line
24 3a) yank: y'k
25 3b) delete: d'k
26 4) move to destination line
27 5) put with P or p
29 #### Apply regex to an arbitrary number of lines
31 1) mark the first line: mk
32 2) mark the last line: ml
33 :'k,'ls/regex/power/g
35 #### Add # to block of text
37 :'k,'ls/.*/#&/
39 #### Remove trailing whitespace of block of text
41 :'k,'ls/\ *$//
43 #### Write file as root
45 :w !doas tee %
47 #### Diff the file on disk with the file in the buffer
49 :w !diff -u % -
51 #### Make a backup of the file on disk
53 :!cp % %.bak
55 #### Sort all lines
57 :%!sort
59 #### Sort paragraph
61 !}sort
63 <sub><sup>} won't be shown in the command.</sup></sub>
65 #### Sort from current line to EOF
67 !Gsort
69 <sub><sup>G won't be shown in the command.</sup></sub>
71 #### Uniq all lines
73 :%!uniq
75 #### Uniq paragraph
77 !}uniq
79 <sub><sup>} won't be shown in the command.</sup></sub>
81 #### Uniq from current line to EOF
83 !Guniq
85 <sub><sup>G won't be shown in the command.</sup></sub>
87 #### Join all lines
89 :%j
91 #### Select a column (3rd) from formated text seperated by ':'
93 :%!awk -F':' '{print $3}'