Here are some of the fundamental things you'll need to do when you edit a document in vi.
Starting vi
To start vi, just type the command- vi
- vi <filename>
Quitting vi
To exit vi and return to the UNIX shell, type :q. If you have made changes to the buffer since the last time you saved it to disk, vi will say "No write since last change (":quit!" overrides)". Type :q! to exit without saving or :wq to exit with saving.Getting help
vi does not have an on-line help system.You can temporarily exit to the shell and see the man page by typing the command :!man vi.Vim editor has 3 mode:
Command mode: Cursor movement, change, delete, yank, put, search
Insert mode: type in new text, return to command mode with <ESC>
Ex mode: configuring, exiting, saving, search and repalce
Cursor motion
In addition to basic cursor motion, vi provides some other handy cursor motion functions:
- 0 (number zero) or ^ (Shift-6) moves the cursor to the start of the current line.
- $ moves the cursor to the end of the current line.
- w moves the cursor forward to the next word.
- b moves the cursor back to the previous word.
- 1G moves the cursor to the start of the buffer. *
- G moves the cursor to the end of the buffer. *
- #G moves to the line where # is the line number.
- Control-F moves the cursor forward one screen.*
- Control-B moves the cursor backward one screen.*
- Control-D moves the cursor forward one half screen.*
- Control-U moves the cursor backward one half screen.*
- /x searches forward for string x.*
- n searches forward for next occurence of found text.*
- ?x searches backward for string x.*
- N searches backward for previous occurence of found text.*
Inserting and deleting text
Deleting text is easy but neither the Backspace nor Delete key will delete a character. Here are some ways to delete text:
- x deletes forward one character.
- X deletes backward one character.
- D or d$ deletes from the point to the end of the line.
- dw deletes forward one word.
- dd deletes one line.
- #dd deletes multiple lines where # is the number of lines to delete
Cutting and pasting text regions
Changing text
Here are some ways to replace text using c (change) and r (replace) commands:- cw allows the current word to be replaced until terminated with Escape.
- cc allows the current line to be replaced until terminated with Escape.
- C or c$ allows the rest of the line to be replaced until terminated with Escape.
- r allows the current character to be replaced by the next character that is typed.
- R allows all text to be replaced until terminated with Escape.
0 nhận xét:
Post a Comment