Here is a summary of some of the recent learning about VIM
Blog Park-Bang Bang sauce Good * * *
1.Introduction
Linux in the text interface under the document editor has: Emacs,pico,nano,joe and vim and so on.
Why you should learn vim (VIM is the advanced version of VI)
(1) Almost all systems will be built into the VI, the other editors do not necessarily exist
(2) Many of the individual software editor interface will be active call VI
(3) Vim has the ability to edit the program, active in font color to identify the correctness of the grammar
(4) The program is simple, the editing speed is quite fast
(The lower-right corner of the edit window in VI mode does not display line numbers.) )
2.VI Total is divided intothree different modes: General mode, edit mode, instruction column command mode
(1) vi open the document, directly into the general mode.
In this mode you can use the "up or down" button to move the cursor, you can use "delete character" or "Delete whole line" to process the document content, you can also use "copy paste" to process your file data.
(2) After pressing "I,i,o,o,a,a,r,r" to enter the editing mode from the general mode. To return to normal mode, you must press the "ESC" key to exit edit mode.
(3) Press ":/?" In any of the three buttons, you can move the cursor to the bottom of the line, then from the general mode into the Instruction column command mode (between the edit mode and the instruction column mode is not switchable). It can provide you with search information, read, save, replace characters, leave VI, display line number and other actions.
3. General modeMove CursorThe method
(1) H or LEFT ARROW key: Move one character to the left
(2) J or DOWN ARROW key: Move down one character
(3) K or UP ARROW key: Move up one character
(4) L or RIGHT ARROW key: Move one character to the right
(5) Move n lines to *: Enter N, then press the corresponding action
(6) Ctrl+f: Move down one page
(7) Ctrl+b: Move up one page
(8) Ctrl+d: Move Down half page
(9) Ctrl+u: Move up half page
(x) n<space>: Enter N, then press space space, the cursor will move n characters to the right
(11) 0 or home key: Move to the front character of this line
(12) $ or END key: Moves to the last face character of this line
4. General modeSearch and replaceThe method
(1)/word: In the current cursor down search, Word is the string you want to search, after entering/word, press ENTER key.
(2) Word: Search the current cursor up, Word is the string you want to search, enter word, press ENTER.
(3): n1,n2s/word1/word2/g: Find word1 This string between lines N1 and N2 and replace it with WORD2
(4): 1, $ss/word1/word2/g: Find word1 This string in line 1th to the last line and replace it with WORD2
(5): 1, $ss/word1/word2/gc: Find word1 This string in line 1th to the last line, and replace it with Word2, and give the user confirmation before replacing
5. In general modeDelete, copy and paste
(1) X,x: In a line of words, X deletes a character backwards; X is a character to be deleted forward
(2) Nx: Remove n characters backwards
(3) DD: Delete the entire line where the cursor is located
(4) NDD: Delete the down n line where the cursor is located
(5) D1G: Remove all data from the first row of the cursor
(6) DG: Removes all data from the last row of the cursor
(7) D0: Delete the cursor to the front of the line character
(8) d$: Delete the cursor to the last character of the line
(9) YY: The line where the cursor is copied
Nyy: The next n line where the cursor is copied
(one) y1g: Copy all data from the cursor to the first row
YG: Copy all data from the last row of the cursor
Y0: Copy all data from the character of the cursor to the beginning of the line
y$: Copy all data from the character of the cursor to the end of the line
(p,p:p) To paste the copied data on the next line of the cursor; p to paste the copied data on the previous line of the cursor
(+) U: Restore previous action
(+) Ctrl+r: Redo the last action
(18).: decimal point, which represents repeating the previous action
6.keys available in edit mode
(1) I,i: Enter insert mode. I insert from the current cursor, and I start the insertion at the first non-whitespace character of the current row.
(2) A,a: Enter insert mode. A is inserted from the next character at the current cursor, and a is inserted at the last character of the current row.
(3) O,o: Enter insert mode. o Inserts a new line from the next line where the current cursor is located, and O inserts a new row for the previous line in the current row.
(2) R,r: Enter insert mode. R replaces only the character of the cursor at a time; R will always replace the text of the cursor until the ESC key is pressed
7.keys available in instruction column mode
(1): w: Write the edited data to the document
(2): w!: Forces the edited data to be written to the document if the file property is read-only. Finally, the ability to write is related to System account permissions.
(3): Q: Leave VI
(4): q!: If you have modified the document, do not want to save, use! To force leave and not store documents
(5) ZZ: If the document is not modified, leave if the document has been modified, then leave after saving
(6): W[filename]: Save edited data to another document
(7): R[filename]: Appends data from another document to the current position of the cursor
(8): n1,n2 w [filename]: Stores data from row N1 to N2 as another document
(9):!command: The result of executing command from VI to command column mode temporarily
(Ten): Set Nu: Display line number
(one): Set Nonu: Suppress line numbers
8.vim ofTemporary archive, rescue recovery and warning message when opening
(1) Introduction
When we use VIM to edit the filename document, Vim creates a temporary archive named. FILENAME.SWP in the current directory of filename. Your action on filename will be recorded in this temporary archive. If the system is disconnected for some reason and the edited document is not stored, the FILENAME.SWP will be able to perform the rescue recovery function.
(2) Analog system disconnection
After opening the document for editing, in the general mode of VIM, when you press CTRL + Z, VIM will be thrown into the background to execute. Next, close the terminal panel directly. This is equal to the system disconnection, just the operation of the document has not been saved to.
(3) Warning message when opening
After the system is disconnected, open the document again vim filename, a warning message appears
Question one: You may edit this file with others at the same time-find another person and ask him to end the operation of the document. Or choose to turn on Read only (O) mode
Problem two: The system is not well-known cause vim interrupted--if the previous Vim action is not saved, you can press R (ecover), then vim will load the. FILENAME.SWP content to recover the document.
Note: After you recover the document,. FILENAME.SWP is not automatically deleted, remember to manually delete it, or each time you open filename There will be a warning message.
9.Block Selection
(1) Key
V: Character selection, where the cursor passes through the white selection
V: Row selection, the line that the cursor passes through is reversed white selection
Ctrl + V: Block selection, you can select the data in the direction of the rectangle
Y: Copy the anti-white place
D: Remove the anti-white place
(2) Application
The first step: Enter the document, the cursor moves to a place, in general mode, press the CTRL + V key, then press the left and right keys to select the Block
Second step: Press the Y key to copy, then the anti-white block will disappear
The third step: Move the cursor to the place you want to paste, in general mode, press the P key to paste operation
10.Multi-document editing
(1) Puzzle: Each vim is independent, unable to perform NYY operation in document A of VIM1, and then go to VIM2 's document B for P operation.
(2) Resolution: Use the command to open multiple documents at the same time under a vim to edit-->vim file1 file2
(3) Press the key (use in general mode):
: N: Edit Next document
: N: Editing the previous document
: Files: Lists all the documents that are currently open for VIM
11.Multi-window function
(1) Puzzle: There is a large document, need to compare the data before and after, if you use the next page ctrl+f, the previous page ctrl+b to run before running after the inspection will be very inconvenient.
(2) FIX: Generate multiple windows in the same vim
First step: Open a document vim file1, enter ": SP" in general mode, will generate another window, the document is displayed File1
The second step: You can also enter ": SP File2" in the general mode, another window will be generated, the document displayed is also file2
Step three: You can use the ctrl+w+ down ARROW key (JK key) to switch between multiple windows
12.Environment Presets
(1) Introduction: The overall Vim setting value is placed in the/ETC/VIMRC, but it is not recommended to modify it. However, you can modify the document ~/.VIMRC, if it does not exist, you can create a new one, and then write the desired preset value.
(2) commonly used presets: (Can be entered in general mode: set all to check)
Set Nu---Displays line numbers (not shown as set Nonu)
Set Hlsearch---high brightness search (not shown as set Nohlsearch)
Set Aotoindent--Auto indent (does not display set Noaotoindent)
Set ruler--Displays the status bar in the lower right corner
Set Showmode--Displays the status bar in the lower left corner
Syntax on--Displays different colors according to program-related syntax (does not show syntax off)
(The annotation information in ~/.VIMRC begins with double quotation marks: "Annotation: Here is the line number shown)
13.The garbled problem of Chinese coding
The Chinese code has BIG5 and UTF8 two kinds, ifgarbled appearance, to consider:
(1) Your Linux system supports the default language data: This is related to/etc/sysconfig/i18n
(2) Your terminal interface Bash's language: This is related to Lang's parameter
(3) The original code of your document
(4) software to open the terminal, such as the Windows interface under GNOME
The most important is the 34th, as long as these two points are consistent, basically will not have garbled.
Two.encoding of converted documents
Iconv--list--List of languages supported by the ICONV command
Iconv-f Original code-t new encoding filename [-o newfile] (from A to B)
To view the encoding type of a document: file filename
Linux--vim