Vim Common commands

Source: Internet
Author: User

First, open the file

Vim filename #打开文件, the cursor is placed on the first line

Vim/pattern filename #打开文件, line with cursor pattern matching

Vim–r filename #恢复上次意外中止的编辑文件

Second, the general mode of cursor positioning

Ctrl+f #屏幕向下移动一页

Ctrl+b #屏幕向上移动一页

Ctrl+d #屏幕向下移动一页

Ctrl+u #屏幕向上移动一页

0 or home button #移动光标到行首

The $ or END key #移动光标到行尾

H #移动光标到屏幕最上方的行

M #移动光标到屏幕中间的行

L #移动光标到屏幕最下方的行

G #移动光标到文档最后一行

NG #移动光标到文档n行

GG #移动光标到文档首行

N<enter> #下移光标n行

Third, the general mode of editing the text

x                     Delete the character at the cursor  
dw                   Delete to the beginning of the next word    
dg                   Delete rows until end of file    
dd                   Delete entire row    
db                   delete the words in front of the cursor    
:n,md             Delete n rows     from line m;
D , d$              is removed from the cursor at the end of the line

u                    Undo Last modification  
u                    undo all changes to the current line

YY puts the contents of the current row into a temporary buffer
Nyy the contents of n rows into a temporary buffer
P puts the text in the temporary buffer after the cursor
P put the text in the temporary buffer before the cursor
NDD Delete n rows into a named buffer in parentheses, omitting n indicates when the forward
C Delete the current line and enter edit mode

Iv. text substitution and lookup in edit mode

: s/aa/bb/g replace AA with BB in all strings containing AA that appear on the line where the cursor is located
: s/\/bb/g replaces all AA occurrences of the cursor with BB, replacing only the word AA.
:%s/aa/bb/g replaces AA in all occurrences of a document with a BB in a string containing AA
: 12,23s/aa/bb/g replaces AA with BB in all strings containing AA from 12 rows to 23 rows
: 12,23s/^/#/will add # characters from Line 12 to line 23
:%s= *$== Remove any extra space at the end of the line
: g/^\s*$/d deletes all empty lines that do not contain characters (spaces are not included).

/xxx (? xxx) means searching the entire document for a string matching xxx,/means looking down,? Represents an upward lookup. Where xxx can be a regular expression, about the formal type is not much to say. Generally case-sensitive, to be case-insensitive, you must first enter: Set ignorecase


Five. Edit Multiple documents

Vim filename1 filenam2 Simultaneous editing of two files

: N Enter edit filename1

: N Enter edit filename2

Six, multi-window editing

Vim filename1 Edit filename1

: SP filename2 Sub-window edit filename2

CTRL+W+J switching between two windows

Ctrl+w+k switching between two windows

:d iffthis Comparison of two files

: VSP Split window switches to horizontal mode

VII. Archiving and exit

: W writes the edited document to disk

: w! Force Write file

: Wq writes the document to disk and exits vim

: Q Quit Vim

: q! Force exit Vim

ZZ modifies the document to save the exit, or not to save it

: W FileName writes the document to filename

: R filename Read in filename

: n1,n2 w FileName writes N1 to N2 line to filename

:! command to execute commands


This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1616287

Vim Common 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.