1.9 KiB
1.9 KiB
Why vi Rocks
vi is the de facto standard Unix editor, you find it in every *NIX derived OS.
Here you will find a collection of commands, command sequences in vi(1)/ex(1) or with 3rd party unitilities which make vi rock. These all work with at least nvi 1.79 and 2.1.3 (unicode).
Helpful documents:
- Roman Zolotarev: Edit text with vi(1)
- Jeff W: vi help
- Maarten Litmaath: vi reference
- alphanrrrd: extremely concise cheatsheet
- ViEmu: Graphical vi cheatsheet
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 destination line
5) put 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
Add # to block of text
:'k,'ls/.*/#&/
Remove trailing whitespace of block of text
:'k,'ls/\ *$//
Write file as root
:w !doas tee %
Diff the file on disk with the file in the buffer
:w !diff -u % -
Make a backup of the file on disk
:!cp % %.bak
Sort all lines
:%!sort
Sort paragraph
!}sort
Sort from current line to EOF
!Gsort
G won't be shown in the command.
Uniq all lines
:%!uniq
Uniq paragraph
!}uniq
Uniq from current line to EOF
!Guniq
G won't be shown in the command.
Join all lines
:%j
Select a column (3rd) from formated text seperated by ':'
:%!awk -F':' '{print $3}'