Linux text Compiler VI

Source: Internet
Author: User

First, what is VIM/VI?

Vim/vi is a powerful full-screen text compiler that is the most commonly used text compiler on Linux platforms,

Used to create, edit, and display text files (the programming platform under the Linux platform) is mainly used for the writing of some script programs

Note: There are no menus, only commands.

Second, VIM/VI working mode

1 command Command mode VI filename into the command mode by default, the commands entered here will not be displayed on the console.

2. Insert Insert mode to edit the text mode, press ESC to return to command mode

3, edit mode through: conform to enter, and then enter some commands and so on, press ENTER to return to the command mode.

Third, the Common VI command

  Insert Command (enter command from command mode, enter insert mode, then enter text, ESC returns command mode)

a attaching text after the cursor

· A insert text at the end of our line

• I inserting text before the cursor

· I start inserting text at the bank

O. Inserting a new line under the cursor

· O insert a new line on the cursor

  Position command

H Left

J. Under

K On

L Right

$ move to end of line

• 0 move to the beginning of the line

· H Move to upper screen

· M moves to the center of the screen

· L move to the bottom of the screen

:set Nu Set line number

:set Nonu Cancel line number

GG to First line

G to last line

NG to Nth row

:n to Nth row

  Delete command

• x Delete the character where the cursor is located

NX Delete the n characters after the cursor

dd Delete cursor row, ndd delete, n rows

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

  · D Delete from the cursor to the end of the line

:n1,n2d Delete a specified range of rows

  Copy Cut command

yy, Y copy as Forward

Nyy, NY copy current line

DD cut as you move forward

NDD cut the current row n rows

P, p is pasted below or above the current cursor line

  Replace and Cancel commands

• R replaces the character at which the cursor is located

· R replace the character at the beginning of the cursor and press ESC to end

• U cancel the previous action

 Search and Replace commands

/string searches forward for specified string, ignoring case when searching (: Set IC on, set Noic off)

• N looking after from the trip

· N looking forward from behind

%s/old/new/g Full Text replace the specified string 1

n1,n2s/old/new/g Replace the character in a certain range old into new, (g means global, replace all not confirm, change to C to confirm)

 Save Exit Command

:wq Save and exit

· ZZ Save exit

:q! Do not save exit

:w save plus filename means Save As

IV. Application Skills

:r file names are imported into the currently edited file

:! command to execute Linux commands in vim mode

:map shortcut key definition commands

: Map ^p (ctrl+v+p) i#<esc> ctrl+p is a shortcut key for inserting # at the beginning of the line (I), and then returning to command mode (ESC)

Continuous line Comment

: Unmap

: n1,n2s/^/#/g ^ Represents the beginning of a line, which represents a comment at the beginning of a n1~n2 row

: N1,n2s/^#//g the "#" at the beginning of the line to cancel the comment (there is no substitution in the middle of the statement)

: N1,n2s/^/\/\//g the beginning of the insertion//, which uses the escape character \

Replace

: AB mymail [email protected] Replace MyMail, mnemonic with my mailbox. For memory shortcut keys

: Unab mymail un-defined

Linux text Compiler VI

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.