Vim usage Summary

Source: Internet
Author: User

This is my summary of some basic usage, which may be helpful to new users. Lele is better than zlele, right!

Note: The following black colors provide common functions for VI and Vim, while the red color is specific to VIM (VI improved. Vim is usually installed on both UNIX and Linux.
Three statuses
Command: Any input will be used as an editing command instead of on the screen. Any input will be immediately reflected.
Insert: Any input data is placed in the edit register. Press ESC to switch back to the command mode.
Escape: a command with ":" or "/" as the leading line appears in the bottom line of the screen. Any input is treated as a special command.
Leave Vi
: Q! Leave Vi and discard the edited content in the buffer.
: WQ writes data in the buffer zone to the disk and leaves VI.
Same as WQ.
(Note --: X indicates file encryption, which must be different from: X indicates disk exit)
Enter input mode
A (append) adds data after the cursor.
A is added by the end of the row.
I (insert) adds data before the cursor.
I. Add the information at the beginning of the row.
O (open) adds a row under this row for data input.
O adds a row above this row for data input.
Delete and modify
X deletes the character of the cursor.
X deletes the previous field of the cursor.
R replaces the character of the (replace) cursor with the character following this command. For example, RA replaces the character of the cursor with.
R enters the replacement status until ESC.
S. Delete the character of the cursor and enter the input mode until ESC.
S. Delete the row where the cursor is located and enter the input mode until ESC.
Move the cursor
M <A-z> set bookmarks <A-z>
'<A-z> move to bookmarks <A-z>
0 to the beginning of the row
$ Move to the end of the row.
E. Move to the last letter of the next word.
W moves to the first letter of the next word.
B moves to the first letter of the previous word.
^ Move to the first character of the row.
H. Move to the first line of the window.
M moves to the middle of the window.
L move to the last row of the window.
G to the last row of the file.
+ Move to the first character of the next column.
-Move to the first character in the previous column.
: N is moved to column N of the file.
N + column N after the cursor is located.
N-column N before the cursor position.
<Ctrl> <G> shows the row number, file name, the row number of the last row in the file, and the percentage of the row number of the cursor to the total row number.

(Vim) basic usage of cursor movement:
(You only need to combine the above functions, so you don't have to explain them one by one !)
Ge B w e
Begin certificate --- → -- →
This is-a line, with special/separated/words (and some more ).
Accept-items -- ----------------- → --- →
Ge B w e

Moving Windows
<Ctrl> <F> the window rolls down a page.
<Ctrl> <B> the window rolls a page.
<Ctrl> <D> the window is rolled down for half a page.
<Ctrl> <u> the window is rolled up half a page.
<Ctrl> <E> the window rolls a row to the next volume.
<Ctrl> <Y> the window rolls a row to the upper part.
Cut, copy, and delete
Operator + scope = command
Operator
D cut
Y replication.
P paste, Which is used with D and Y. The last d or y data can be placed in the row and column where the cursor is located.
C modification, similar to the group and of Delete and insert. Delete A Word Group, sentence, and other materials, and insert new materials.
Scope
E is the last character of the string from the cursor position.
W is the first character from the cursor location to the next string.
B is the first character from the cursor position to the previous string.
$ From the cursor location to the last character of the row.
0 is the first character of the row from the cursor position.
Whole row action
Dd deletes the entire row.
D. Delete All characters after the cursor in the unit of action.
CC modifies the entire line.
YY copies the row of the cursor to the memory buffer.
Undo)
U.
U restores all changes to the row of the cursor.
(Vim) u can undo commands multiple times, undo one operation at a time until this operation starts.
(Vim) Ctrl + R can restore the content before undo, and can be restored multiple times by multiple times.
Search and replace
/String to search for the string after the cursor.
? Returns the string before the cursor.
N to continue searching for the next same string.
N continues to search for the next same string.
% Find the matching characters.
S searches for a range of rows and columns.
G.
: 1, $ S/old/new/g change all the "old" in the file to "new 』.
: 10th S/^ // insert 5 blank spaces at the top of the rows from 20th.
(Vim)
/Enter the query content behind the string to save it to the buffer. You can select the previous content using the forward slash.
In addition, move the cursor Under the selected word and press *. You can select this word as a query character to avoid the trouble of inputting a long string of characters.
(Vim) case-insensitive replacement
First, press V to enable the selection function, and then use the character keys → keys to select the characters to be replaced. If the lowercase letters are changed to uppercase letters, press u; otherwise, press u;
If you want to select a word, you can press V, W, and U/U. In this way, you can change the case of the characters without deleting the words and then retyping them.

Data Connection
J sentence connection. Connect the next row of the cursor to the end of the row.
Environment setting
: Set all: List of configurable Environment Variables
: Current value of the Set environment variable
: Set nu to set the row number of the data.
: Set Nonu cancel row number setting.
: Set AI is automatically scaled in and out.
: Set noai cancels automatic contraction.
(Vim)
: Set ruler: The current cursor position is displayed in the lower right corner of the screen and changes as the light moves. It occupies a small amount of screen space and is convenient to use. It is recommended to use this function.
: When set hlsearch is used, all matching content is highlighted.
: Set nohlsearch disable this function.
: Set incsearch enables Vim to position matching points during the input string.
: Set nowrapscan disable the automatic search loop function, that is, find the end of the file and end the search. The default status is automatic loop.

Ex command
Read and Write Data
: 10th, 20th test writes data from rows to the test file.
: 10th W> test: add the data of rows 20th to rows after the test file.
: R test reads the data of the test file into the end of the editing buffer.
: E [filename]: edit a new file.
: E! [Filename] discard the modified file and edit the new file.
: Sh: Enter the shell environment, exit with exit, and return to the editor.

:! Run the command CMD and return to the editor.
Delete, copy, and move
: 10, 20 d delete data from rows 10th to rows 20th.
: 10 days to delete data from the first row.
: % D Delete the entire editing buffer.
: 10, 20co30: Copy data from rows 10th to rows 20th to rows 30th.
: 10, 20mo30: Move the data of row 10th to row 20th to row 30th.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.