Vi/vim Delete and other commands

Source: Internet
Author: User
Tags first string



Delete one line: DD






Delete a word/cursor after the remainder of the word: DW






Delete Current character: X






The line part after the cursor: d$









Text deletion



DD Delete a row



d$ delete a line of characters starting with the current character






NDD deletes n rows starting at the current line



DW Deletes a word starting with the current character



NDW delete N words starting with the current character






D synonymous with d$






d) Delete to the beginning of the next sentence






D} Delete to the beginning of the next paragraph



D Enter Delete 2 rows



NDW or NDW deletes the n-1 characters at the beginning and after the cursor.
D0 deleted to the beginning of the line.
d$ deleted to the end of the line.
NDD deletes the current row and its subsequent n-1 rows.
x or X to delete one character.
Ctrl+u deletes the text entered under input mode.
^r Recovery U operation
J Merge the next line to the end of the current line
V Select a row
^v the selection of the rectangle after pressing the ^V
AW Select words
IW internal words (no spaces)
As select a sentence
is select sentence (no spaces)
AP Select Paragraph
IP Select paragraph (no spaces)
D Delete to end of line
X, y Delete and copy contain highlighted areas

DL deletes the current character (same as x command function)
D0 Delete to the beginning of a row
d^ Delete to the first character position of a line (excluding spaces or tab characters)
DW Delete to the end of a word
d3w Delete to the end of a third word
DB Delete to the beginning of a word
DW deletes the end position of a word with a space separator
DB Delete to the beginning of a word with a space separator
d7b Delete to the beginning of the first 7 words with spaces as separators
d) Delete to the end of a statement
D4) Delete to the end of the fourth statement
D (Delete to the beginning of a statement
d) Delete to the end of a paragraph
d{Delete to the beginning of a paragraph
d7{the 7th paragraph position before the current paragraph start position is deleted
DD Delete When moving forward
D/text Delete the position of the typeface specified in text
Keep moving forward until the next occurrence of the word (but not including the word) between the content
The DFC deletes the position from the text where the character "C" appears, moving forward until the next occurrence of the character (including the character) between the contents
DTC deletes the current row until the next character "C" appears between the contents of the position
D Delete to the end of a line
d$ Delete to the end of a line
5DD Delete 5 rows from the current line
DL delete content until the last line on the screen
DH deletes the contents of the first line until the screen
DG delete content until end of work buffer
D1G Delete content until the working buffer starts








Move cursor in VI
On k
h l left and right
  Under j

^ Move to the first non-space character of the line
w Move a word forward and treat the symbol or punctuation as a word
W moves a word forward without treating symbols or punctuation as words
b Move a word backward and treat the symbol or punctuation as a word
B moves a word backwards without treating symbols or punctuation as words
(The cursor moves to the beginning of the sentence
) The cursor moves to the end of the sentence
{ Cursor moves to the beginning of the paragraph
} Cursor moves to the end of the paragraph
H cursor moves to the top line of the screen
M cursor moves to the middle of the screen
L cursor moves to the last line of the screen
0 to the beginning of the line
$ to the end of the line
Gg to the top
G to the end of the page
Line number +G jumps to the specified line
n+ cursor moves down n lines
N- Move the cursor up n lines
Ctrl+g Query current line information and current file information

Fx jumps right to the character x of the line (x can be any character)
Fx jumps to the left to the character x of the line (x can be any character)

Tx is the same as fx, the difference is before jumping to the character x
Tx is the same as Fx, the difference is that after jumping to the character x

C-b scrolls up one screen
C-f scrolls down one screen
C-u scrolls up half a screen
C-d scrolls down half a screen
C-y scrolls up one line
C-e scrolls down one line

Nz Scrolls the nth line to the top of the screen and rolls the current line to the top of the screen without specifying n.
Enter and Exit VI command
Vi filename Open or create a new file and place the cursor at the beginning of the first line
Vi +n filename Open the file and place the cursor at the beginning of the nth line
Vi + filename Open the file and place the cursor at the beginning of the last line
Vi +/pattern filename Opens the file and places the cursor at the first string that matches pattern
Vi -r filename A system crash occurred during the last edit with vi, restoring filename
Vi filename ... filename Open multiple files and edit them one by one

ZZ quit vi and save
:q! Exit vi without saving
:wq exit vi and save
Repeat operation
.        Repeat Last Action
Auto-Completing
C-n      match next keyword c-p      match previous keyword
Insert
o Enter a new line below the cursor and place the cursor at the beginning of the new line to enter insert mode.
O Same as above, above the cursor.

a Enter insert mode after the cursor.
A Same as above, before the cursor.


R enters the replacement mode until Esc is pressed
Set xxx Sets the XXX option.
Row merge
J        Merge The following line behind the bank
VI Find and Replace commands
/pattern searches for pattern from the beginning of the cursor to the end of the file
?pattern searches for pattern from the beginning of the cursor to the beginning of the file
n Repeat the last search command in the same direction
N repeats the last search command in the reverse direction
% Find paired parentheses
:s/p1/p2/g Replace all p1 in the current line with p2. If you want to ask each user for replacement, you should use the gc option.
:n1,n2s/p1/p2/g Replace all p1 in the nth to n2th lines with p2
:g/p1/s//p2/g Replace all p1 in the file with p2

.*[]^%~$ has special meaning in Vi. If you need to find it, you should add the escape character "\".
Find some options to set highlighting
:set hlsearch setting highlighting
:set nohlsearch turn off highlighting
:nohlsearch turns off the highlight that is currently set
Incremental Lookup
:set incsearch set incremental lookup
:set noincsearch turn off incremental lookup
Delete in VI
x delete the character under the current cursor
Dw deletes the rest of the word after the cursor.
d$ Deletes the rest of the line after the cursor.
Dd Delete the current line.

c function and d are the same, the difference is that after entering the delete operation, enter INSERT MODE
Cc also deletes the current line and then enters INSERT MODE
Change character
Rx       Changes the character under the current cursor to X (any character x) ~        




Keyboard macro Actions
Qcharacter starts recording macros, character is any character from a to z
q Terminate the recording macro
@character calls a previously recorded macro
Recovering from a false operation
u Undo the last executed command
U Correct the operation of the line before
Ctrl+R Redo
Operate the frame in VI
C-w c-n increase the frame
C-w c-c reduce frame
C-w c-w switch frame
C-w c-r exchanges two frames
Block operations in VIM


Vim supports up to 26 clipboard


Select the block First select one with v, C-v, V, then copy with y, then paste with p.
  Yy copy the current entire line
  Nyy copy the n lines of the current line start
  ?nyy saves the current line of the cursor and the contents of the next n lines into the register?, where ? is a letter and n is a number
  ?nyw saves the current line of the cursor and the next n words in the register?, where ? is a letter and n is a number
  ?nyl saves the current line of the cursor and the next n characters in the register?, where ? is a letter and n is a number
  ?p Paste the contents of register ? after the cursor position. If ? is a complete line copied with yy,
         Paste below the line where the cursor is. Here? Can be a letter or a number
  ?P Paste the contents of register a before the cursor position. If ? is a complete line copied with yy,
         Paste on the line where the cursor is. Here? Can be a letter or a number
  Ay[motion]
            Ay$ Copy the cursor position to the end of the line and save it in register a
            Ayft copies the cursor position to the first letter t of the current line and saves it in register a


All of the above instructions can be removed from a work, then y,p works on the unnamed register (all D,c,x,y objects are saved here).


Cut/Copy/paste


All deleted contents are saved automatically and can be pasted with P key.


Option settings for VI
All lists all option settings
Term set terminal type
Ignorance ignores case in search
List shows tab stops (Ctrl+I) and end-of-line markers ($)
Number display line number
Report shows the number modified by the line-oriented command
Terse displays a short warning message
Warn displays NO write information if the current file is not saved when transferring to another file.
Nomagic allows special characters without "\" in front of search mode
Nowrapscan prohibits vi from starting at the other end when the search reaches both ends of the file
Mesg allows vi to display information written by other users to write on their own terminal. 
Tips


Automatic formatting of code GG=G









In Vi/vim, jump to the end of the file shortcut key:






File start: Shift + G



End of File: G g












From:http://dsec.pku.edu.cn/~jinlong/vi/vi.html






From:http://www.caole.net/diary/vim.html#sec-1



Vi/vim Delete and other commands


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.