Linux learning notes-Explanation of Vim operation commands and learning notes-vim

Source: Internet
Author: User

Linux learning notes-Explanation of Vim operation commands and learning notes-vim

Linux Study Notes-Vim operations

1. Vim Introduction

Vim is a powerful full-screen text editor,

Is the most common text editor on Linux/UNIX,

It is used to create, edit, and display text files.

Vim has no menu and only commands

2. Insert command

Command

Function

A

Insert the cursor after the character

A

Insert at the end of the row where the cursor is located

I

Insert the cursor before the character

I

Insert at the beginning of the row where the cursor is located

O

Insert a new line under the cursor

O

Insert a new line on the cursor

3. Locating commands

Command

Function

: Set nu

Set row number

: Set nonu

Cancel row number

Gg G

To the first line to the last line

NG

To row n

: N

To row n

Command

Function

$

Move to end of line

0

Move to the beginning of the line

4. delete commands

Command

Function

X

Delete the character at the cursor

Nx

Delete the last n characters at the cursor location

Dd

Delete row where cursor is located, ndd Delete n rows

DG

Delete the row where the cursor is located to the end of the file

D

Delete the content from the cursor location to the end of the line

: N1, n2d

Deletes a row in the specified range.

5. Copy and cut commands

Command

Function

Yy

Copy current row

Nyy

Copy n rows below the current row

Dd

Cut current row

Ndd

Cut n rows below the current row

P, P

Paste the cursor to the bottom or row of the current cursor

6. Replace and cancel commands

Command

Function

R

Replace the character at the cursor

R

Replace the character from where the cursor is located, and Press Esc to end

U

Cancel the previous operation

7. Search and replacement commands

Command

Function

/String

Case Insensitive when searching a specified string: set ic

N

Searches for the next occurrence location of a specified string.

: % S/old/new/g

Replace the specified string in full text

: N1, n2s/old/new/g

Replace a specified string within a certain range

8. Save and exit the command

Command

Function

: W

Save changes

: W new_filename

Save as specified file

: Wq

Save changes and exit

ZZ

Shortcut Key, save the modification and exit

: Q!

Exit Without saving changes

: Wq!

Save the modification and exit (available to the file owner and root)

9. Vim skills

Import command execution result: r! Commands (such as date and df)

: R! Dare inserts a date at the cursor

: R file path (import the specified file content to the cursor)

:! Which ls: view the path of the ls command

Define shortcut key: map shortcut key trigger command

Example: map ^ p I # (Cttrl + P indicates to jump to the beginning of the line and add comments ("#")

: Map ^ B 0x (cttrl + V indicates jumping to the beginning of the line to delete the first character)

Continuous Line comment: n1, n2s/^/#/g

Remove "#" at the beginning of the line: n1, n2s/^ # // g

Remove "//" from the beginning of the line: N1, n2s/^/\/g

Replacement: AB aa bb@126.com

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.