Vim Editor
Text editor, word processor
Nano, SED
Vi:visual Interface (Visual Interface)
Vim:vi improved
Mode editor, full screen editor
One: Open file
# Vim/path/to/somefile
Vim +#/path/to/somefile Open/path/to/somefile and locate the file # line
Vim +/path/to/somefile opens/path/to/somefile and is located at the bottom of the file
Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched to the PATTERN
Edit mode/Command mode: Copy, paste, delete line ...
Input mode: input content to file
Last-line mode: File management commands
Opens the Vim editor, which is in edit mode by default.
Patterns can be converted from one to the other.
Edit-Input
I: In front of the character of the current cursor, converted to input mode;
A: After the character of the current cursor, convert to input mode;
O: Under the current cursor line, create a new row, convert to input mode;
Capital
I: Convert to input mode at the beginning of the line where the cursor is currently located;
A: At the end of the line where the current cursor is located, convert to input mode;
O: On the line of the current cursor, create a new row, convert to input mode;
input - Edit
Edit --and last-line mode (only accessible from edit mode)
Commands that can be executed by the last-line mode:
10d: Delete line tenth in the file
10,20D: Delete lines tenth through 20th in the file;
Set Nu: Display line number
! ls/etc/: Execute shell command without affecting the current file edit
Last-line mode-- edit
Input mode to the last line mode cannot be converted directly;
Two: Close the file
three: Move cursor (Edit/ Command mode)
Last line mode jump: directly to the travel number, enter can
Four, turn screen operation
Ctrl+f: Turn down one screen and flip one screen to the end of the file
Ctrl+b: Turn up one screen and turn one screen to the file header
Ctrl+d: Flip Down half screen
Ctrl+u: Flip up half screen
V. Delete a single character
Vi. Delete command D
Seven, paste command: P
The deleted content is not purged immediately, but is saved in the memory buffer.
The last deletion of the content, can be pasted into any specified place, can be pasted multiple times;
P:
If you delete or copy the entire line, paste it to the place where the cursor is located;
If the copied or deleted content is a non-whole line, paste it to the back of the character where the cursor is located;
P:
If the whole line is deleted or copied, paste it to the top of the cursor;
If the copied or deleted content is a non-whole line, paste it in front of the character where the cursor is located;
Viii. Copy command: Y
Usage with d command
YY: Copy one line
3yy, y0, y$ ...
Nine, first delete the content, and then into the input mode (i.e.: Replace or modify)
X. REPLACEMENT command
R: Replace single character
R: Enter the replacement mode, similar to the Insert key. ESC Exits replacement mode
Xi. Revocation of edits
U:undo, undo the previous edit operation, you can use continuous u, undo the first n edits
Note: VI or VIM only saves the last 50 edits in the memory buffer, which means that we can only undo the last 50 edits at the most recent time.
#u: Undo the edit operation of the most recent # times directly.
Undo undo: Undo/Redo Last undo operation: Ctrl+r
12. Repeat the previous edit operation
13. Visualization Mode
V: Select by character, select to perform all of the above editing operations (d delete, y copy, etc.)
V: Select by Rectangle block, select by row
14. Find
/pattern: From file header to tail lookup
? PATTERN: From the current cursor line, to the file header, looking backwards
XV, find and replace
Use the S command in the last-line mode, using the same usage as sed.
For example: Move the document from the current line (.) all lowercase He that starts at the bottom of the document is replaced with the uppercase he
:., $-1s/he/he/g
Full-text replacement:
: 1,$ or:%
1,$, which means that from the first line to the last line, the percent semicolon also refers to the full text.
Exercises:
Replace ftp://instructor.example.com/pub in the/etc/yum.repos.d/server.repo file with Http://172.16.0.1/yum
Key
%s/ ftp: \ /\ /instructor\ . Com\ /pub/ http : \ /\ /172.16.0.1/ GI
%s@ftp://instructor\.example\.com\/pub@/http172.16.0.1/yum @gi
16. How to open multiple files
Vim FILE1 FILE2 FILE3
: Next: Switch to the next file
:p Rev: Switch to previous file
: Last: Switch to final file
: First: Switch to file one
Vim rc.local Init
The first file is displayed by default;
Switch to next file: Next
Switch to last file: prev (note: Before you switch to the previous file, you must save the edited file, otherwise the switch does not pass)
Exit: Exit All
: QA
: Qall
17, split screen display a file
Look at the previous content to edit the following
Ctrl+w,s: Horizontal splitter window
Ctrl+w,v: Vertical splitter window
Toggle window: Ctrl+w,arrow (Upper and lower left and right arrows)
Exit:
: Q Exits a window
: QA all exits, close all windows
--------------------------------------------------------
Horizontal splitter window:
Ctrl+w, loosen, then press S
ctrl+w+ down/On the arrow, toggle the cursor to the top/bottom of the window to edit.
Vertical splitter window:
Ctrl+w, release, then press V
18, sub-window display multiple files
Window 1 shows file 1, window 2 shows file 2
horizontal split display, for example: Vim- o FILE1 FILE2
Vertical Split display, for Example:vim- o FILE1 FILE2
19. Save part of the current document as another file
Use the W command in the last row mode
: W
: W/path/to/somewhere
: Addr1,addr2w/path/to/somewhere
20. Fill in the current file with another file content (merge two files)
: R/path/to/somefile
21. Interacting with the shell
Enter in the last line mode:
:! COMMAND
#COMMAND不支持alias别名命令
22. Advanced Topics
1. Display or suppress line numbers
: Set number--Set Nu
: Set Nonu
2. Ignoring or distinguishing character casing
: Set IC
: Set ignorecase
: Set Noic
: Set Noignorecase
3. Set auto Indent (useful when writing scripts)
: Set Autoindent
: Set AI
: Set Noai
4. Set highlighting (found text highlighting)
: Set Hlsearch
: Set Nohlsearch
5. Syntax highlighting
: Syntax on
: Syntax off
23. Vim Configuration file
Global:VIM/ETC/VIMRC
Local (User level):vim ~/.VIMRC
About Vim's exercises:
The system comes with the vimtutor, do it once a day, each control in half an hour to fix, became.
This article is from the "Cold Tea" blog, please be sure to keep this source http://miaocbin.blog.51cto.com/689091/1665883
How to use the VIM editor