Use of vim (text compiler) under Linux

Source: Internet
Author: User

Vim (text compiler):

Vim is a text editor developed from VI.

Some of the command actions of VIM:

Insert command:

A Insert in the word specifier the cursor
A Insert at the end of the line where the cursor is
I Insert in the word match either the cursor
I Insert at the beginning of the cursor
O Insert a new line under the cursor
O Insert a new line on the cursor

Locate command:

: Set Nu (number) Set line number
: Set Nonu Cancel line number
Gg Jump to the first line
G Skip to last line
NG Jump to Nth row
: N Jump to Nth row
$ Move to end of line
0 Move to the beginning of the line

Delete command:

X Delete the character at the cursor location
Nx Delete the first n characters at the cursor location
Dd Delete the cursor in the row
Ndd Delete N rows
Dg Delete the line of the cursor to the end of the file
D Delete the line from the cursor to the end of the line
: n1,n2d Delete a specified range of rows

Copy and cut commands:

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 or P

Paste at or above the line where the current cursor is located

To replace the Cancel and search commands:

R Replaces the character at which the cursor is located
R Replace with cursor, press ESC to end
U Cancel the previous action
/string Search for specified string (: Set IC) ignoring case
N Searches for the next occurrence of the specified string
:%s/old/new/g Full-text replace the specified string (/g can be replaced by/C) to ask before replacing
: n1,n2s/old/new/g Replace a specified string within a certain range

Save and Exit Commands:

: W Save changes
: w new filename 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 or root) to use

Move Cursor ( edit mode )

1, character-by-word movement:

H: Left

L: Right

J: Next

K: Up

#h: Moving a # character

2. Move in Word units

W: Move to the beginning of the next word

E: Jumps to the ending of the current or next word

B: Jump to the beginning of the current or previous word

#w: Moving # words

3, in-line jump:

0: The absolute beginning

^: first non-whitespace character at the beginning of a line

$: absolute end of line

4. Jump between rows

#G: Jump To Line #

GG: First line

G: Last line

5, the last line mode

.: Indicates when the forward

$: Last line

#: Line #

+#: Down # line

Some tips for using vim:

Import Command Execution result:

: R! Command
For example:
: R file Name
: R/etc/issue imports content from/etc/issue to the cursor location.
:! Which command view command path
: R! Date imports the current time at the cursor location


define shortcut keys:

map Shortcut Trigger command
For example:
define a shortcut key comment line
: Map ^p (ctrl + V + P) i#<esc>
Delete a comment
: Map ^b 0x


Continuous Line comments:
: Set Nu
: n1,n2s/^/#/g (^ Indicates the beginning of the line)
Delete a comment
: n1,n2s/#//g (delete all lines starting with # Delete including # in line)
: n1,n2s/^#//g (delete only # at the beginning of the line)

Special: Add two characters//
: n1,n2s/^/\/\//g header plus//characters


Replacement:
AB a B After input a replaces a with B
For example:
AB mymail [email protected] After entering MyMail, replace MyMail with the following mailbox


all shortcuts can be conveniently written in the configuration file in advance: (it may not exist)
Root:/ROOT/.VIMRC
Normal User:/HOME/USERNAME/.VIMRC

Use of vim (text compiler) under Linux

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.