The VIM compiler in rookie eyes

Source: Internet
Author: User
Tags exit in

Vi (Visual Interface) is a text editor with a common text compiler that has ASCII encoding, Unicode encoding, and so on. Vim is VI improved: is the enhanced version of VI, Vim is a modal editor.

There are 3 modes of VIM in the work:

- edit mode: Also called command mode,: default mode, move cursor, cut/paste text;

- Insert mode: Enter content in a text file;

- last line mode: Vim built-in command interface, execute VIM's built-in command, save, exit, etc.

As shown in the following:

650) this.width=650; "Src=" http://upload-images.jianshu.io/upload_images/6908438-9e6d50749cdca3ff?imageMogr2/ auto-orient/strip%7cimageview2/2/w/1240 "alt=" 1240 "/>

The translation of the pattern between the three words is explained:

Command –> Insert:

I: In front of the character of the current cursor, switch to input mode;

I: Converted to input mode at the beginning of the line at which the cursor is currently located

A: At the end of the line where the current cursor is located, convert to input mode

A: After the character of the current cursor, switch to input mode;

O: At the bottom of the current cursor line, create a new row and switch to input mode;

O: At the top of the current cursor line, create a new row and switch to input mode;

Insert –> Command:

Esc

Command –> Extension:

:

Extended –> Command:

Esc,enter

Note: There is no direct switch between insert mode and Extended command mode.

EX: Using ESC2 or ENTER to return to command mode, there will be no:

Q exit

q! forced exit

W Save

Wq or x Save and exit

wq! or x! When a file is read-only to the current user right, it can be forced to save and exit (root and current file owner only)

Open File

Vim +#: Open the file and leave the cursor at the beginning of line #

Vim +: Open file, navigate to last line, default line end

Vim +/pattern: Open the file and leave the cursor at the beginning of the line that matches the first PATTERN

–B file binary mode open files

–d file1 file2 ... Compare multiple Files

-m file read-only open files

Ex file or vim–e directly into ex mode

If the file exists, the file is opened and the content is displayed

If the file does not exist, create it when you save it for the first time after editing

Close File

1. Extended Mode close File

: Q exit

: Wq Save and exit

: q! Do not save and exit

: W Save

: w! Forcibly saved

: wq! Forcibly save exit

2. Exit in command mode

ZZ: Save and exit

ZQ: Do not save exit

Move cursor (edit mode)

1, character-by-word movement:

H: Left

L: Right

J: Next

K: Up

#h: Represents moving # Characters

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: Indicates 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 current page jump:

H: Top M: Page Middle row L: Bottom of page

# # VIM Edit Command # #

1. Flip Screen

CTRL+F: Flip one screen down

Ctrl+b: Turn up one screen

Ctrl+d: Flip Down half screen

Ctrl+u: Flip up half screen

2. Delete a single character

X: Delete a single character at the cursor location

#x: Delete the # characters at the beginning of the cursor

XP: Swap the position of the character where the cursor is located and the character after it

Delete command: D

The D command is used in combination with the jump command

d$: Delete to end of line

d^: Delete to non-empty header

D0: Delete to the beginning of the line

DW: Delete the first word of the next word

De: Delete the ending of a jump to the current or next word

DB: Delete the first word that jumps to the current or previous word

DD: Deletes the current cursor in the row

DD: Delete the line containing the line of the current cursor;

Paste Command P

P: If you delete or copy to an entire row, paste to the bottom of the line where the cursor is located, and if the copied or deleted content is a non-full row, paste it after the character that contains the cursor

P: If you delete or copy to an entire row, paste to the top of the line where the cursor is located, and paste to the front of the character where the cursor is located if the copied or deleted content is not a whole line

Copy command y

Usage with d command

#yy: Copying Multiple lines

Y: Copy Entire row

Modify: Delete content first, then convert to input mode

C: Usage with d command

CC: Delete the current line and enter new content

C: Delete the current cursor to the end of the line and switch to insert mode

Undo Edit Operation U

U: Undo the previous edit operation

#u: Undo Recent # edits directly

The continuous u command undoes the previous n edit operations

Undo the most recent undo action: Ctrl+r

# # Extension Mode # #

1. Content definition

.: Indicates when the forward

: Last line., 1 current line to the second penultimate line

# specific # lines, such as 2 for line 2nd

+#: The starting line from the left #, plus the number of rows on the right # for example: 2,+3 represents 2 to 5 rows

# #: From the left # indicates the starting line to the right # indicates the end line

% full text, equivalent to 1,$

2. Find

/pattern from the current cursor at the end of the file

? PATTERN looks at the file header from the current cursor location

N in the same direction as the command

N with the command counter direction

Find and replace

Use the S command in the last-line mode

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

Modifier:

I: Ignore case

G: global substitution; By default, each row replaces only the first occurrence of the

GC: Global substitution, asking before each replacement

Find separators in substitutions/can be replaced with other characters, such as

[Email protected]/[email protected]/[email protected]

s#/boot#/#i

Multi-file Mode

Use Vim to edit multiple files

Vim FILE1 FILE2 FILE3

: Next switches to the next file

:p Rev Switch to the previous file

: Last switch to final file

: first to switch to file one

: Q Exits the current file

: Wall Save All

: Qall Quit all

: Wqall Save all files and exit

# # Multi-window Mode # #

Split-screen display of a file

Ctrl+w, S: Horizontal splitter window

Ctrl+w, V: Vertical splitter window

Toggle the cursor between windows:

Ctrl+w, arrow (h,j,k,l or arrow keys)

: QA Closes all windows

Edit multiple files in a split window

Vim-o: Horizontal Split display

Vim-o: Vertical Split display

Q can exit multi-window mode

/pat1/,/pat2/

Starting from the first line that was matched to the pat1 pattern, until the first time it was

PAT2 match to end of line

#,/pat/: From line # start to first match to Pat

/pat/,$: From first match to Pat to last line

How to use: followed by an edit command

D (Delete)

Y (copy)

W File: Save a range of rows to a specified file

R file: Inserts all content from the specified file at the specified location

Advanced Topics

1. Display or suppress line numbers

: Set Nu

: Set Nonu

Nu = number

2. Display ignores or distinguishes character case

: Set IC

: Set Noic

IC = ignorecase

3. Set Auto Indent

: Set AI

: Set Noai

AI = autoindent

4. Check the found text highlighting or canceling

: Set Hlsearch

: Set Nohlsearch

5. Syntax highlighting

: Syntax on

: Syntax off

Note: The feature is currently valid and you need to modify the configuration file if you want to permanently

Configuration file Definition:

/ETC/VIMRC for all Users

~/.VIMRC for the current user

Classroom Exercises

1. Copy the/etc/profile to/tmp/directory and use the Find replacement command to remove the white space characters from the beginning of the/tmp/profile file

%s/^[[:blank:]]+//g

Ideas:

The Find content is a blank character with the first plus ^, the replacement content is blank, and G indicates a global substitution.

2. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # number to the beginning of the line beginning with a blank character for each line of/tmp/functions with the Find replacement command

%s/^[[:spacge:]]/#/g

or%s/^ ([[: Space:]])/#\1/g

or%s/^[[:space:]]/#&/

Train of thought: The second method uses a back reference, and \1 represents a reference [[: Space:]], #号后都为空白字符. The third method & corresponds to the preceding whitespace character.

3. Copy the/etc/rc.d/init.d/functions file to the/tmp directory and replace the/etc/sysconfig/init in the/tmp/functions file with the/var/log

%s/\/etc/sysconfig/init/\/viar/log/gi

Idea: here \ means escape, GI indicates global substitution, ignoring case

4. Delete the # number at the beginning of all lines in the/tmp/functions file that begin with # and have at least one blank character after #

%s/^#[[:space:]]{1,}//g

Idea: \{1,\} means matching the preceding command at least 1 times, looking for: ^#[[:space:]]\{1,\}, replacing the content: to delete so it is empty.


The VIM compiler in rookie eyes

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.