Linux text editing tool vim and linuxvim

Source: Internet
Author: User

Linux text editing tool vim and linuxvim

Vim has three modes: general mode, edit mode, and command mode.


* General mode:When you edit a file using vim filename, the normal mode is used when you enter the file.. In this mode, you can move the cursor up or down, delete a character, delete a row, and copy or paste one or more rows.


* Editing mode: In normal mode, a character cannot be modified, but only in editing mode. SlaveIn normal mode, enter edit mode. You only need to press a key (I, I, a, A, o, O, r, R). When you enter the editing mode, the INSERT or REPLACE line appears at the bottom of the screen. Back from the editing mode to the general mode, you only need to press the ESC key in the upper-left corner of the keyboard.


* Command mode:In normal mode, enter":" Or "/" to enter the command mode. In this mode, you can search for a character or string, save, replace, exit, and display the row number.



Move the cursor in Normal Mode

H or left direction key

Move a character to the left

J or downward arrow key

Move the cursor down a character

K or the up arrow key

Move the cursor one character up

L or the right arrow key

Move the cursor one character to the right

Ctrl + f or pageUP

Move one page forward

Ctrl + B or pageDOWN

Move one page behind the screen

Ctrl + d

Move half of the screen forward

Ctrl + u

Move half of the screen back

+

Move the cursor to the next column with a non-space character

-

Move the cursor to the previous column of a non-space character

N spaces (n is a number)

Press the number n and press the space. The cursor moves n characters to the right. If the number of characters in the row is less than n, the cursor continues to move from the downlink to the right until n

0 (number 0) or Shift + 6

Move to the beginning of the row

Shift + 4

That is, '$' is moved to the end of the row.

H

Move the cursor to the top line of the current screen

M

Move the cursor to the center of the current screen

L

Move the cursor to tHe bottommost line of the current screen

G

Move cursor to the last line of text

NG (n is a number)

Move to the nth line of the text

Gg

Move the first line with the text

N press enter (n is a number)

Move the cursor down n rows

 


Search and replace in Normal Mode

/Word

Search for a string named word after the cursor. When the first word is found, press "n" to continue searching for the next one.

? Word

Search for a string named word before the cursor. When the first word is found, press "n" to continue searching for the previous one.

: N1, n2s/word1/word2/g

Search for the word1 string between n1 and n2 and replace it with word2. You can also Replace "/" "#"

: 1, $ s/word1/word2/g

From the first row to the last row, search for word1 and replace it with word2.

: 1, $ s/word1/word2/gc

The role of c is to be confirmed by the user before replacement.

 


Copy, paste, and delete

X, X

X deletes one character backward, and X deletes one character forward.

Nx (n is a number)

Delete n characters from the backend

Dd

Delete the row where the cursor is located

Ndd (n is a number)

Delete the next n rows of the cursor

D1G

Delete all data from the row where the cursor is located to the first row

DG

Delete all data from the row where the cursor is located to the last row

Yy

Copy the row where the cursor is located

Nyy

Copy n rows down from the row where the cursor is located

P, P

The data copied by p is pasted from the next row of the cursor, and P is pasted from the previous row of the cursor.

Y1G

Copy all data from the row where the cursor is located to the first row

YG

Copy all data from the row where the cursor is located to the last row

J

Combines the row where the cursor is located with the data of the next row into the same row.

U

Restore previous operations

 


Edit mode

I

Insert characters before the current character

I

Insert characters at the beginning of the current row

A

Insert characters after the current character

A

Insert characters at the end of the current row

O

Insert a new row under the current row

O

Insert a new row into the current row

R

Replace the character of the cursor only once

R

Always Replace the character of the cursor until you Press ESC

 


Command mode

: W

Save edited text

: W!

If the text attribute is read-only, force save

: Q

Exit vim

: Q!

Do not save or exit after editing

: Wq

Save and exit

: E!

Restore a document to its original state

ZZ

If the document is not changed, it is not stored and left. If the document has changed, it is stored and left, equivalent to: wq

: W [filename]

Save the edited file as filename

: R [filename]

Read the content of the filename document under the row where the current cursor is located

: Set nu

Display the row number at the beginning of each row

: Set nonu

Cancel row number

N1, n2 w [filename]

Save the content from n1 to n2 as filename.

:! Command

Temporarily leave vim to run a linux Command, for example :! Ls/home: List Files in the/home directory temporarily, and then press enter to return to 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.