1 / 8

CIS 218

vi. CIS 218. vi basics. Why vi(m)? Universal editor in LINUX/UNIX. Compatible with UNIX system files. Other packages: pico, emacs, nano - not available on certain UNIX systems. vi somefile copies somefile into memory buffer, does not edit disk copy

kamana
Télécharger la présentation

CIS 218

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. vi CIS 218

  2. vi basics • Why vi(m)? Universal editor in LINUX/UNIX. Compatible with UNIX system files. • Other packages: pico, emacs, nano - not available on certain UNIX systems. • vi somefile copies somefile into memory buffer, does not edit disk copy • Three modes determines how keystrokes are interpreted by vi – command mode, text mode operator line(: / or ?) Command mode is default when you enter vi. The command you enter determines the next mode. • You hit Esc to return to command mode from either text or operator mode.

  3. Navigation • Arrow keys OR • H(up)J(down)K(left)L(right) • Determines cursor location by record #, column # on the operator line • Use set -o or set -o vi to normalize terminal command line usage to vi standards.

  4. Locate text • /text – locate text (down) • / - repeat last find • ?text Search backward (up) for text

  5. Change text • i – insert text • x – delete a character • r – replace a character • R – replace text until Esc • yy p – copy a line • dd – delete a line • <Enter> or <Return> - ends a line or record • Many others

  6. Text Substitution • See also Stream Editor or sed • :n1,n2s/old/new/gc …. where - : operator line command - n1 is the beginning line. “.” for current line, line#, 1 or ^ is first line, % for all - n2 is the ending line number. “.” for current line, line# or "$" for EOF - s means to substitute text matching the (old) pattern with (new) pattern - g (global) optional. Substitute all occurrences on the indicated lines. Otherwise substitutes only the first occurrence on the indicated lines. - c (confirm) is optional. It indicates you want to confirm each substitution before vi completes it Examples :%s/old/new/g - Substitutes old with new throughout the file :.,$s/old/new/g - Substitutes old with new from the current cursor position to the end of the file :^,.s/old/new/g - Substitutes old with new from the beginning of the file to the current cursor position :& - Repeats the last substitute (:s) command

  7. Saving results • :w - write file • :w filename - write as different filename • :w>>filename - append to filename • :w!- force overwrite of file • :wq – save results and quit on some systems also :ZZ • :wq! – force overwrite of file and quit • :q - quit (no save) only if no changes • :q! - quit (no save)

  8. Spell check • Spell check a document: spell < file • This will output misspelled words to STDOUT in ordinary English, not a syntax checker for shell

More Related