Linux Text Editor Vim * * *

Source: Internet
Author: User
Tags linux text editor

Vim is a powerful full-screen text editor, which is the most commonly used text editor on Linux, and its role is to create, edit, display text files, vim no menus, only commands.

Vim working mode

$ VI myfile.msg

ESC back to command mode from insert mode

1.vim Insert Command:

Command

Role

lowercase a

Insert in the word specifier the cursor

Capital A

Insert at the end of the line where the cursor is

lowercase I

Insert in the word match either the cursor

Capital I

Insert at the beginning of the line where the cursor is

Lowercase O

Insert a new line below the cursor

Capital O

Insert a new line above the cursor

Please practice your own actions to enhance your memory.

2.vim Positioning Command:

Command

Role

: Set Nu

Set Display line numbers

: Set Nonu

Cancel line number

Gg

Exactly one line

G

To the last line

NG

to Nth row

: N

to Nth row

$

Move to end of line

0

Move to the beginning of the line

3.vim Delete command:

Command

Role

X

Delete the character at the cursor location

Nx

Delete the first n characters at the cursor location

Dd

Delete Row of cursor, NDD delete n rows

Dg

Delete the line from the cursor to the end of the file

D

Delete the cursor at the end of the line

: n1,n2d

Delete a specified range of rows

4.vim copy and Cut commands

Command

Role

Yy

Copy when moving forward

Nyy

Copy the following n rows of the current row

Dd

Cut when moving forward

Ndd

Cut the following n rows of the current row

P, p

Paste at the current cursor row or line

5. Vim replacement and Cancellation commands

Command

Role

R

Replaces the character at which the cursor is located

R

To replace a character from where the cursor is located, press the ESC key to end

U

Cancel Last Action

6. Vim Search and search replace command

Command

Role

/string

Searches for the specified string,

Ignore case when searching:: Set IC

De-Ignoring casing:: Set Noic

N

Searches for the next occurrence of the specified string,

:%s/old/new/g

Replace the specified string with full text

: n1,n2s/old/new/g

Replaces a specified string within a range, N1,N2 represents the number of rows

7. Vim Save and Exit commands

Command

Role

: W

Save changes

: w NewFileName

Save as specified file

: Wq

Save changes and exit

Zz

Shortcut keys, save changes and exit

: q!

Do not save changes to exit

: wq!

Force save changes and exit, file owner and ROOT to use

Summarize vim common command actions:

Vim Command mode insert mode edit mode

Insert Command AIO

Positioning: Set Nu:n

Delete x NX DD NDD

Copy and cut yy-p combinations, dd-p combinations

replacing and recovering r/r u

Search and replace/keyword N Find next match: Range/To replace keyword/replace with keyword/g

Save exit: Wq zz:q!

8. Vim Usage Tips:

8.1 Import File command:: R file name

:!which ls To view the path of the command;

You can import command execution results directly into the vim file you are currently editing, in the following format:: R! [Command],

Example: R!date

8.2 Defining shortcut keys map Shortcut trigger command

Example:

: Map ^h [email protected]<esc>, this command represents the definition of shortcut key ctrl+h, the command to insert a mailbox, and then back to command mode;

8.3 Continuous navigation notes

: n1,n2s/^/#/g Add Comment, ^ denotes beginning of line

: n1,n2s/^#//g Uncomment

: n1,n2s/^////g

8.4 Replacement

: AB myemail [email protected] Custom some common characters, then enter in vim when typing Myemail will automatically change to [email protected]

8.5 Vim edit mode configuration file

The home directory creates the. VIMRC configuration file, located in/HOME/USERNAME/.VIMRC, which configures common edit mode commands, such as

Set Nu

Map ^p i#<esc> Save.

Linux Text Editor 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.