Vim text editor
1, the role:
- Create or modify text files;
- Maintaining Linux systems in a variety of configuration files;
2, Linux common text editor:
- vi: Unix-system default text editor;
- vim: enhanced version of the vi editor, also known as customary vi;
1, three operating modes Vim text editor
Three modes of vim text editor: command mode, input mode, line mode.
- ---- command mode by a, i, o and other key ----> input mode
- Input Mode ---- ---- press esc> command mode to return
- Command Mode ---- enter a colon: ----> line mode
- Line mode ---- ---- press esc> command mode to return
2, the basic operation of the editor vim
(1) Move the cursor:
Quick Jump :( command mode inline)
- Go to the first line: Home key or "^" key (i.e.: shift + 6), the number "0";
- Jump to the end of the line: End key or "$" key (i.e., shift + 4);
Quick Jump :( command mode within the document)
- Jump to the first line of the document: 1G or gg
- Jump to last line of the document: G
- Jump to file the first line #: #G
(2) display line number
:( line number line mode)
- : Set nu (display line numbers)
- : Set nonu (cancel the display line numbers)
(3) copy, paste, delete :( command mode)
copy:
- Cursor line (current line): yy
- # Line starting from the cursor line: #yy
Paste:
- p (lowercase p): pasted to the front of the cursor target position;
- P (uppercase P): pasted after the cursor target position;
Delete:
(1) To delete a single character: the X-, del, the Delete
(2) delete a row of characters:
- The current cursor line: dd
- # Line starting from the cursor line: #dd
- Delete all the characters before the current cursor to the beginning of the line: d ^
- To delete all the characters after the current cursor to the end of the line: d $
(4) internal inquiry :( command mode)
Query from top to bottom: / string to look
to find from bottom to top:? String you want to findLocation Down: n
Positioning up: N
(5) Revocation and save :( command mode)
Revoked:
- Revoked once: u
- Undo multiple times: execute it several times u command
- Undo all operations: U (uppercase)
Storage:
- Save: ZZ (uppercase)
(6) Save and exit line mode :()
: w (save)
: w /root/test.txt (Save)
: q (quit without change)
: q! (exit, modify the content without saving exit)
: WQ (save and exit)
(7) to open or edit the document :( line mode)
: E /root/yum.conf (editing documents)
: r /root/test.txt (open a document)
(8) the contents of the file to replace :( line mode)
: S /root/yum.conf (in the first row of the query cursor old string, and replaced with new string)
: S / old / new / G (in rows where the cursor strings to find all of the old, and are replacement) as new string
: #, # S / old / new / G (Find all the old strings between specified rows, and are replaced with new string)
:% S / old / new / G (in Find the full text of all the old strings, and are replaced) as new string
:% S / old / new / gc (Find all the old strings throughout the text, and are replaced with new strings, but each must be confirmed )