Vim Introduction/vim color display and move cursor/VIM general mode move cursor/VIM general mode copy, cut and paste

Source: Internet
Author: User

    • 5.1 Vim Introduction 5.2 Vim color display and move cursor
    • 5.3 Vim General mode move cursor
    • 5.4 Vim General mode copy, cut and paste

Vim is an upgraded version of VI

Vim with color display

Installing Vim:yum install-y vim-enhanced

Vim is divided into three modes: General mode, edit mode, command mode

General mode: DD,YY,PP,

Edit mode: I,a,

Command mode: q,wq! , Q!,set Nu,set Nonu;nohl (no highlight not highlighted);

X can also be saved to exit, similar to WQ;

If no action Wq will save the time of Mtime change

X does not save the time of the change;

The configuration file is colored, and there is no color to copy anywhere else.

Some files will be different from different file types, color display;

Shortcut keys:

GG jumps to the beginning of the first line;

G move to the end of the line;

Shift+o the cursor points before the first line and enters edit mode;

H J K L lower left upper right Arrow

SPACEBAR to move to the right;

Number + Space: 11 times how many characters to move to the right;

Page UP: Ctrl + F (forward)

Page DOWN: ctrl+b (back)

NG (n is a number) moves to the first line

The number 0 or shift+6 moves to the beginning of the bank;

Shift+4 moved to the end of the bank;

Copy yy; 3 yy Copy the following 3 lines, p paste the following, p paste to the top;

Paste pp;

Cut: 5 dd clip below 5 lines, p paste below, p paste on top;

Undo U

Back to undo: Control+r

Delete a line of DD

Select a character anywhere: v Select and then do the operation

X means to delete a character forward

X means to remove one character backwards

NX means to remove n characters backwards

Enter edit mode

Lowercase i in the current word match either insert

Uppercase I inserts at the beginning of the line where the cursor is located

Uppercase O Inserts an edit line above the cursor

Lowercase o Inserts an edit line below the cursor

Lowercase a inserts a write after the cursor (A is an abbreviation for after)

Uppercase a inserts an edit at the end of the line where the cursor is located

/After the cursor looks for a matching string---/word-----SHIFT + N to look up

? To find a specific string before the cursor----? Word

1,100s/user/xiaobo/g------1 to 100 lines, s means to start replacing, replace the User with Xiaobo, and G to replace global

Without G, only the first one will be replaced;

Replace AA with BB, find string and replace:%s/aa/bb/g-----% indicates all rows

Replace all: 1, $s/ftp/xiaobo/g-----$ means all the time to the last line;

/etc/hosts/xiaobo.com to replace the character/etc/hosts with xiaobo.com

1, $s/\/etc\/hosts/xiaobo.com/g

where \ is de-justified,/etc/hosts is recognized as a string

You can also write this:

1, $s #/etc/hosts#xiaobo.com#g

Practice:

# Cp/etc/dnsmasq.conf/tmp/1.txt

#vim/tmp/1.txt

Do not highlight Nohl

(1) Move Down, right, left, and up 6 characters (6j 6l 6h 6k) respectively.

(2) Two pages (two times ctrl+f and Ctrl+b respectively) downward and upward respectively.

(3) Move the cursor to line 49th (49G).

(4) Move the cursor to the end of the line, and then move to the beginning (Shift+4, shift+6).

(5) Move to the last line of the 1.txt file (G).

(6) Move to the first line of the file (GG).

(7) Search for "DNSMASQ" in the file and count the number of occurrences of the string (/dnsmsq then press N).

(8) Replace the DNSMASQ from line 1th to line 10th with DNS (: 1,10s/dnsmasq/dns/g).

(9) Restore the previous action (U).

(10) Replace all the etc in the entire file with a CTE (: 1, $s/etc/cte/g).

(11) Move the cursor to line 25th, delete the string "ly" (25G then press L to move the cursor to the right to find "ly", press V to select, and press X).

(12) Restore the previous action (U).

(13) Delete line 50th (50G dd).

(14) Restore the previous action (U).

(15) Delete all contents of 第37-42 line (37G 6DD).

(16) Restore the previous action (U).

(17) Copy the contents of line 48th and paste it below line 52nd (48G yy 52G p).

(18) Restore the previous action (U).

(19) Copy the contents of the 第37-42 line and paste it onto line 44th (37G 6yy 44G P).

(20) Restore the previous action (press U).

(21) Move the contents of the 第37-42 line below line 19th (37G 6DD 19G p).

(22) Restore the previous action (press U).

(23) Move the cursor to the first line, the 1th line to the "#!/bin/bash" (First press GG, the cursor to the 1th line, and then press the letter A, enter the editing mode, and > Cursor to the end of the line, to modify the operation, after completion, press ESC).

(24) Insert a new line below line 1th and enter "# hello!" (Press O to enter edit mode, while the cursor goes down another line, enter "# hello!" )。

(25) Save the document and exit (press the ESC key and enter ": Wq").

Vim Introduction/vim color display and move cursor/VIM general mode move cursor/VIM general mode copy, cut and paste

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.