Introduction to Vim

Source: Internet
Author: User

Vim is an upgraded version of VI, more than the VI features
Vim when editing the file is color display, vi is no color display
The default is not installed Vim, need to install this package
Yum Install-y vim-enhanced
Vim has three modes, namely General mode, edit mode, command mode
General mode: DD Delete command, yy copy command P paste command, etc.
Edit mode: After I was the editing mode, you can change the file additions and deletions,
Command mode: Do not press I before, or press ESC in edit mode to type Command mode to find replacements for files, and so on. Saving exits is also done in command mode.

When editing the/etc/passwd file is color display, when the copy to/tmp/passwd, when editing/tmp/passwd files, there is no color display
In the CentOS/etc/is placed in the configuration file, so there are colors, when copied to other directories will be the original configuration file as a normal file, all No color

Can edit the/tmp/passwd file in the first line to add a #khaskdjfhkashdf plus this line, and then exit, and then re-edit the color, is blue, that is, in the ordinary file is also color display, but it is necessary to a specific environment to have color.

Change this file to a. sh end of the file, also have color changes,. SH is a shell script format
mv/tmp/passwd/tmp/passwd.sh

/ETC/VIMRC is a vim configuration file, if you need to change, you can change this file, generally keep the default
[Email protected] ~]# VIM/ETC/VIMRC

Move cursor
Can be moved by the left or right key, can also be moved with letters

H: Move the cursor to the left
K: Move Cursor up
J: Move the cursor down
L: Move cursor to right
The space bar also moves right
Numbers plus letters means moving one or a few letters
5h: Move 5 characters to the left
5j: Want to move down 5 lines
5k: Move up 5 rows
5l: Move 5 characters to the right
5 spaces: Move 5 characters to the right

GG: A line of text
G: Last line of text
^, 0: The beginning of the line
$: End of line

50G: Position the cursor to line 50th
Ctrl+b or PageUp: Flip the screen up
Ctrl+f or PageDown: Flip the screen down

DD: Delete a row, also belong to cut, can only cut one row
P: Paste the next line at the cursor location
P: Paste on the previous line where the cursor is located
U: If the last operation is wrong, you can recover 50 times with u recovery (the result of the last save exit is the initial state)
Ctrl+r: If you want to go back to the last step, use Ctrl+r
YY: Copy 5yy copy five Elements
X: Delete one character backwards
Shift+x: To delete a character, it is also possible to add a number
V can be copied or cut from a character to a character, point V and then move the cursor to select the content to be copied or cut, with yy is copied with X is cut

Edit mode
I: Start editing the document at the cursor's current location
I: Start editing at the beginning of the cursor
O: Start editing from the row below the line where the cursor is located
O: Start editing from the top row of the line where the cursor is located
A: Start editing after the next character in the line where the cursor is located
A: Start editing at the end of the line where the cursor is located

Command mode
To find the file format:
/What to look for
such as:/DNSMASQ direct return to highlight the match to find the content,
Press N to find the next
Press N to go up the search

can also be used? Find what you need, the use of N and N and/or vice versa

Replace
: 1,100s/bin/kylin/g
Colon opening
1,100 is the line that needs to be replaced
S is to start replacing
/is the delimiter is to replace the need and replace the separate
G is global, if not added, only replace this file to find the first word that matches

: 1$s/bin/kylin/g is to replace all

If you need to replace a path in a file, or if you need to translate a special character, or change a separator
Both of these are possible.
: 1, $s/\/etc\/hosts/\/etc\/passwd/g
: 1,100s#/etc/host#/etc/passwd#g

Sometimes save quit or quit when you can not go out need to add!
: wq!
: q!
: X is also saved to exit
Wq and X difference: In the change time when the save exit is the same, when entering a file if nothing is done to directly save the exit words Wq is changed mtime, X is not changed mtime

Show line Numbers
: Set Number
Do not display line numbers
: Set Nounmber

Do not display highlighting
: Nohl

Vim Paste Code Auto indent cause all messed up

Reply to Favorites

Use VIM to open a blank document, and then paste the copied code into it, found that it has automatic indentation function, resulting in the pasted text line is more than one line on the right, looks mess. The quicker solution is to enter the document in command-line mode before pasting it
: Set Noai Nosi
Then press ' I ' to enter edit mode, and then paste the copied code content so that it does not automatically indent.

Sometimes, such a method is not good to use, you can try this:

: Set Paste

Introduction to Vim

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.