Linux Learning 5 Vi,vim

Source: Internet
Author: User

1. General mode
Move
h or direction left-------------------left to move
Move under--------------------J or in the direction
K or move------------------on the direction
L or Direction right-------------------right Move


Crtl+f Move down one page (common)
Ctrl+b Move up one page (common)
Crtl+d Move Down half a page
Crtl+u move up half a page



+ cursor moves to the next line of non-whitespace
-Cursor moves to the previous line of non-whitespace
N<space> moves to the nth character of this line
0 move to the head end of this line (common)
$ move to the end of this line (common)
G Move to the last line of this file (common)
NG moves to the nth line of this file, often with: Set Nu
GG moves to the first line of this file, with 1G (common)
n<enter> cursor moves down n rows (common)

Search
/word starts at the cursor position and searches down a string named word (common)
? Word starts at the cursor position and searches up a string named word (common)
n means repeating previous search action (common)
N indicates reverse repetition of previous search action (common)

Search replacement
: N1,n2s/word1/word2/g indicates that word1 is searched between N1 and N2 rows and replaced with word2 (common)
: 1, $s/word1/word2/g means search between the first and last lines to word1 and replace with word2 (common)

: 1, $s/word1/word2/gc means search between the first and last lines to word1 and replace with Word2, but give the user hints when replacing (common)


Delete, copy, paste
X in a row, delete one character backwards, equivalent to [Del] (Common)
X in a row, delete a character forward, equivalent to [Backspace] (Common)
NX continuously removes n characters backwards
DD Delete the line where the cursor is located (common)
NDD Delete the down n rows where the cursor is located (common)
D1G Delete all data from the cursor position to the first row
DG deletes the cursor position to the last row to all data
d$ Delete data from the cursor position to the last character of the line
D0 Delete the data from the position of the cursor to the first character of the line


YY the line where the cursor is copied (common)
Nyy Copy the row of the cursor down n rows (common)
Y1G Copy all data from the row to the first row of the cursor
YG copies all data from the row to the last row of the cursor
y$ Copy the data from the row to the last character of the line
y0 Copy the cursor position to the first character of the line to the data


P Paste the copied data to the next line of the cursor (common)
P paste the copied data to the previous line of the cursor (common)
J combines data from the row of the cursor and the next row into the same row
U revert to previous action, quite with undo (common)
Crtl+r Redo last Action (common)
. Decimal point, repeat the previous action, such as repeat paste, repeat delete, etc. (common)


2. Edit mode
I insert characters in front of the cursor (common)
I insert characters at the head of the line where the cursor is located (common)
A insert character after cursor (common)
A inserts characters at the end of the line where the cursor is located (common)
O Letter O, insert a new line at the next line where the cursor is located (common)
o character O, insert a new line at the top of the cursor (common)
R replaces the character that the cursor is in (common)
R always replaces the text in the cursor until ESC is pressed (common)


3. Command mode
: w Save edited data (common)
: w! If the file property is read-only, then forcibly written, specifically, you write to file permissions.
: Q leave VI (common)
: q! Forced leave does not store files
: Wq storage after leaving (common)
: e! Restore a file to its original state
ZZ If the file does not change, it is not stored away, and if the file is changed, it is stored and left.
: w filename is equivalent to save as file.
: R filename in the editing data, read the data of another file, that is, the content is loaded behind the cursor line
: n1,n2 w filename Saves the N1 to N2 line of this file as a filename file
:! command to temporarily leave the display result of vi Execution command, for example:! Ls/home can view file information in VI
: Set NU Displays line number
: Set Nonu Cancel line number

Vim's visual block function (with the keyboard's upper and lower left and right visible effects, the mouse can not see it)
v character selection, where the cursor passes through the anti-white selection
V-line selection, the line that the cursor passes through is anti-white
Crtl+v block selection, a piece of the place
Y copy anti-white place
D Remove the anti-white place

Multi-file editing
Open multiple Files
Vim filename1 filename2 Filename3 ...
: N Edit Next file
: N Edit Previous file
: Files lists all files that are currently being opened by vim


Multi-window editing
: SP filename opens a new window that, if added with filename, indicates that a new file is opened in a new window, otherwise two windows are the same file content.
Crtl+w+j Press CRTL+W, and then press J, move to the lower window.
Crtl+w+k Ibid., move to the top window.
Crtl+w+q End of departure


Some of the commonly used vim environment settings
: Set Nu Sets line number
: Set Hlsearch Sets the search string to anti-white, if you do not want to set to: Set Nohlsearch
: Set autoindent Auto indent, not auto indent: Set noautoindent
: Set backup is automatically backed up, typically with nobackup, otherwise a backup file will be generated filename~
: Set ruler whether the lower-right corner displays status
: Set Showmode sets the lower left display status as--insert--
: Set backspace= (012) In general, I enter the editing mode with the backspace bar to delete characters, but some versions do not allow, at this time can be set with backspace, when backspace=2, you can delete any characters. 0 or 1 o'clock, you can only delete characters you have just entered.
: Set all to show all environment settings
: Syntax (off/on) turns on syntax rendering.


Experience:
You do not have to set it every time, you can create a configuration file yourself:
Vim ~/.VIMRC
: Set Hlsearch
: Set backspace=2
: Set Autoindent
: Set Ruler
: Set Showmode
: Syntax on

Linux Learning 5 Vi,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.