Differences
This shows you the differences between two versions of the page.
— | appwiki:vi [2021/08/28 08:05] (current) – created ying | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Vi ====== | ||
+ | * built-in command line text editor for Mac and Linux | ||
+ | ===== edit ===== | ||
+ | * search and replace < | ||
+ | // global replace | ||
+ | : | ||
+ | // global replace interactively and case insensitive | ||
+ | : | ||
+ | // global replace limit to 6 occure | ||
+ | : | ||
+ | // replace all with 10-15 lines | ||
+ | : | ||
+ | // live select replace | ||
+ | // ctrl-v to set line range then :s/ /g | ||
+ | |||
+ | // replace whole word only | ||
+ | : | ||
+ | |||
+ | // replace similar whole word | ||
+ | : | ||
+ | |||
+ | // replace wildchar pattern, ball01 ball02 | ||
+ | : | ||
+ | |||
+ | // express | ||
+ | \= | ||
+ | !_\ is the same | ||
+ | ^ start end $ | ||
+ | </ | ||
+ | * delete/cut range < | ||
+ | Deletes lines n through m</ | ||
+ | * delete line containts < | ||
+ | // delete lines contains keyword | ||
+ | :g/keyword | ||
+ | : | ||
+ | |||
+ | // delete blank lines | ||
+ | :g/^\s*$/d | ||
+ | |||
+ | // delete all line NOT with pattern, not start with " | ||
+ | : | ||
+ | : | ||
+ | |||
+ | // delete all line NOT with pattern, contains cat or dog or pig | ||
+ | : | ||
+ | </ | ||
+ | * paste < | ||
+ | ===== concept ===== | ||
+ | |||
+ | 2 modes | ||
+ | * Switch to normal mode: < | ||
+ | * Switch to edit mode: i or a | ||
+ | |||
+ | Quit | ||
+ | * Exit Vi: :q | ||
+ | * Exit Vi (ignore changes): | ||
+ | * Save: :w | ||
+ | * Save and Exit: :wq | ||
+ | * Switch to (edit) an other file: :edit FILENAME | ||
+ | |||
+ | |||
+ | ^navigation |esc; then shortcut | | ||
+ | ^cursor place |h (left) j (down) k (up) l (right) | | ||
+ | ^line start/end |home / end | | ||
+ | ^go to line 78 |:78 | | ||
+ | |||
+ | ^display |cmd | | ||
+ | ^show line number |:set number | | ||
+ | ^off line number |:set nu! | | ||
+ | ^hex mode |:%!xxd | | ||
+ | ^exit hex |%!xxd -r | | ||
+ | |||
+ | ^function |cmd | | ||
+ | ^replace char |r | | ||
+ | ^delete char/line |x / dd | | ||
+ | ^paste |shift+p | | ||
+ | ^find |:/ | ||
+ | ^find next/ | ||
+ | ^replace once on current line |:s/OLD/NEW | | ||
+ | ^replace all on current line |: | ||
+ | ^replace all in range line |:#,# | ||
+ | ^replace all in file |: | ||
+ | |||
+ | |||
+ | [[http:// | ||