Vim Editor (Tenth chapter)

Source: Internet
Author: User

1. Vim Editor

1.1 Vim Basics

VIM has two modes: normal mode, insert mode and last line mode, normal mode can use command, insert mode for editing text use, last line mode for command line

Input I will enter insert mode at the cursor, press ESC to exit edit mode

Built-in commands in normal mode:

H: The cursor moves one character to the left

L: The cursor moves one character to the right

K: Move the cursor up one line

J: Move the cursor down one line

CTRL+F: Flip one screen down

Ctrl+b: Turn up one screen

G: Move directly to Text trailer

#G: Move to the specified # line

GG: Move directly to the text header

Normal mode input: can enter the last line mode, the following is the command of the last line mode

Q: Exit

q!: Force quit is not saved

W FileName: Save the file in another file

Wq: Save exit


1.2 Editing data

X: Delete the single character at the cursor

#x: Delete #-1 characters that contain and follow the cursor

DD: Delete entire row

#dd: Delete the #-1 line containing the cursor and the following

U: Undo Last Action

DW: Delete the word where the cursor is located

d$: Delete the contents of the cursor at the end of the line

A: Append data at cursor position

A: Append data at the end of the cursor line

R Char: The single character at which the cursor is replaced by Char

R text: Use text to overwrite the data at the cursor's original position until the ESC key is pressed


1.3 Copying and pasting

Cut and paste

DD or #dd delete the row, and then move the cursor to the specified position press p to paste the row you just deleted to the cursor location.

Copy and paste

YY: Copy entire row

#yy: Copy contains line of cursor and #-1 line

YW: Copy the word where the cursor is located

y$: Copy cursor at end of line

P: Paste at the cursor location

1.5 Finding and replacing

Find:

/pattern: Looking down from the current position of the cursor

? PATTERN: View from the current position of the cursor

N: Same direction as command

N: Opposite direction to command

Find and replace

S: Complete find and replace in last-line mode

Format: s/What to look for/replace content/modifiers

What to look for: Available modes

What to replace: You cannot use the pattern, but you can use the \1,\2 ... wait for the back reference symbol, and you can use & to refer to the entire content found in the previous lookup;

Modifier:

I: Ignore case

G: Global substitution, default to replace only the first occurrence of each row of matching strings

Find the delimiter in the substitution/can also be replaced by other symbols, for example: [Email protected]@@ s###

Other uses:

%s/old/new/g: Replace all old

%S/OLD/NEW/GC: Replace all old but prompt each time

N,ms/old/new/g: Replaces all old between N and M in a row


This article from "The Boundless" blog, declined reprint!

Vim Editor (tenth chapter)

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.