Vim Usage Basics 2

Source: Internet
Author: User
Tags save file

Frm:http://www.linuxidc.com/linux/2013-05/84031p2.htm

Before the official use of vim, a little appetizer, learn some of the common commands in vim, with these basic commands, so that we can use vim more handy, speed up the efficiency of the work ~

Note: The following commands are intended to be used in Vim's normal mode.

Create/Modify a file

When a file needs to be edited, the file must first exist. You can use VIM to create or modify a file (assuming the file name is hahaya.cc), perform vim hahaya.cc under the terminal, this command will open the hahaya.cc file, and when hahaya.cc this file does not exist, Vim will create the file and open it.

II Open/Save/exit/modify files in vim

(1): E filename <-> Open file filename, note that filename contains the file path

: E ~/hahaya.cc Open hahaya.cc file in home directory

(2) SaveAs filename <-> save file As, note that filename contains the file path

(3): W <-> File Save

(4): Q <-> do not save exit, back to the terminal

(5): q! <-> Do not save forced exits

(6): Wq <-> Save exit

(7): wq! <-> Force save exit

(8): bn <-> When you open multiple files, use this command to switch to the next file

(9): BP <-> When you open multiple files, use this command to switch to the previous file

Three different insertion modes

There are many ways to enter insert mode from Normal mode, here are a few common methods

(1) I <-> insert before cursor, enter into insert mode

(2) A <-> insert after cursor, enter insert mode

(3) O <-> Insert a row after the current line into insert mode

(4) O <-> Insert a row before the current line into insert mode

(5) CW <-> change word, replace the current position of the cursor to the end of the word character, in fact, the actual effect is deleted, into the insert mode

Four simple cursor movements

(1) H <-> move the cursor forward one character

(2) J <-> Move down one line

(3) K <-> Move up one line

(4) L <-> move the cursor backward one character

(5) 0 <-> number 0, move to the line of the cursor

(6) ^ <-> Move to the first position of the bank that is not the blank character (so-called blank characters are spaces, tabs, line feeds, carriage returns, etc.)

(7) $ <-> move to the end of our line

(8) G_ <-> move to the last position of the bank that is not a blank character

(9) G <-> Move to the last line of this file

(Ten) NG <-> Move to Line N of this document

(one) GG <-> move to the first line of this file

Five copy/paste

(1) yy <-> Copy as Forward

(2) Nyy <-> Copy total n rows starting from the current line

(3) P <-> lowercase p, paste the contents of the copy

Six deletions

(1) DD <-> Delete the current line and store the deleted row in the Clipboard, all of which can be pasted using p

(2) Ndd <-> Deletes a total of n rows starting at the current line and stores the deleted rows in the Clipboard, all of which can be pasted using p

Seven Undo

(1) U <-> Undo Last Action

(2) Ctrl-r <-> Press Ctrl and R at the same time to undo the U

Vim in the command is indeed more, so memory is very difficult, even remember, and then do not, then after a period of time will forget, so the best way to learn the VIM command is: more practice, so unknowingly will be the command of VIM firmly remember ~

Vim Usage Basics 2

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.