61 lines
1.1 KiB
Markdown
61 lines
1.1 KiB
Markdown
# Why vi Rocks (WIP)
|
|
|
|
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 />
|
|
These all work with at least [nvi](https://en.wikipedia.org/wiki/Nvi) 1.79 and 2.1.3 (unicode).
|
|
|
|
Tutorials:<br />
|
|
- [Roman Zolotarev: Edit text with vi(1)](https://rgz.ee/vi.html)
|
|
|
|
#### Yank / delete an arbitrary number of lines
|
|
|
|
1) mark the first line: mk
|
|
2) move to last line
|
|
3a) yank: y'k
|
|
3b) delete: d'k
|
|
4) move to new line
|
|
5) paste with P or p
|
|
|
|
#### Apply regex to an arbitrary number of lines
|
|
|
|
1) mark the first line: mk
|
|
2) mark the last line: ml
|
|
:'k,'ls/regex/power/g
|
|
|
|
#### Write file as root
|
|
|
|
:w !doas tee %
|
|
|
|
#### Diff the file on disk with the file in cache
|
|
|
|
:w !diff -u % -
|
|
|
|
#### Make a backup of the file on disk
|
|
|
|
:!cp % %.bak
|
|
|
|
#### Sort all lines
|
|
|
|
:%!sort
|
|
|
|
#### Sort paragraph
|
|
|
|
!}sort
|
|
|
|
#### Uniq all lines
|
|
|
|
:%!uniq
|
|
|
|
#### Uniq paragraph
|
|
|
|
!}uniq
|
|
|
|
#### Join all lines
|
|
|
|
:%j
|
|
|
|
#### Select a column (3rd) from formated text seperated by ':'
|
|
|
|
:%!awk -F':' '{print $3}'
|
|
|
|
|