Use of the VIM editor

Source: Internet
Author: User

Vim Editor:
Full-screen editor: VIM
Vi:visual interface

Vim:
A modal editing Tool:
Edit mode: Command mode
Input mode:
Last-line mode:

Mode conversion:

Edit mode (default)--Input mode:
I:insert, insertion
A:append, inserting after cursor execution
O:new line, new row to insert
I: Insertion at the beginning of the line where the cursor is currently located
A: The end of the line at which the current cursor is located
O: Above New CCB

Input mode--edit mode:
Esc

Edit mode--and last-line mode:
:

Last-line mode--edit mode
Esc

How to open vim:
# VIM
# Vim/path/to/somefile
+#: #为行号: Opens directly at line beginning of # lines
+/pattern: Cursor navigates to the beginning of the first match to the file

The method of turning off vim (most of which needs to be done in the last line mode):
: Q does not change text and exits directly
: q! Force exit
: Wq Save Exit
: x shorthand for the former
: W/path can specify save to path directly
ZZ: Save exit

Cursor Jump:
Jump between characters:
H: Jump left one character
L: Jump Right One character
J: Next Hop one character (small Japanese Japan nasty)
K: Jump up one character

#COMMAND: #为数字, specifying a numeric character jump

Jump between words:
W: The first word of the word
E: The ending of the current or subsequent word;
B: The first word of the current or previous word;

#COMMAND: #为数字, specifying a numeric character jump

In-line jump:
^: jumps to the first non-whitespace character at the beginning of a line;
0: Jump to the beginning of the line, absolute beginning;
$: Jump to the end of the line, absolute line end;

Move between rows:
#G跳转至第 # line:
1G, GG: Jump to the first line
G: Jump to the last line

Move between sentences:
): Skip to next sentence
(: Jump to the previous sentence

Move between paragraphs:
}: Skip to next paragraph
{: Skip to previous paragraph

Edit command:

Character editing:
X: Delete the character at the cursor location
#x: Specify number of deletions, backward

XP: Swap the word and the following character in the cursor

R: replaces the character at which the cursor is located;

Delete command:
D: Delete
d^: Delete the character before the beginning of the line at the current cursor
d$: Delete all characters at the end of the line at the cursor
D0: Delete all characters at the beginning of the cursor

DW, DE, DB

DD: Delete the entire line where the cursor is located

#COMMAND

Note: The deleted content is not cleared and will be saved to the buffer by the Vim editor;

Paste: P (paste, put)
If this copied or deleted content is not a full line
P: Paste at the back of the current cursor;
P: Paste at the front of the current cursor;

If the copied content is a full row (more than one line)
P: Paste below the line where the current cursor is located;
P: Above line;

Copy command: Y, yank
Y
y$, y^, y0
Ye, yw, yb

YY: Copying rows

#COMMAND

Changing the command: C, change
C $, c^, C0
CB, CE, CW
Cc:

#COMMAND

To undo a previous edit operation:
U:undo
Undo the previous edit operation;

#u

Ctrl+r:
Redo the previous undo operation

.: Repeats the previous edit operation

Turn screen operation:
Ctrl+f: one screen backward;
Ctrl+b: one screen ahead;

Ctrl+d: Back half screen
Ctrl+u: Forward half screen

Vim built-in tutorials:
Vimtutor

Vim's last-line mode

        (1) address, delimitation
            : Start_pos,end_pos
                 #: # line;
                 #,#
                 #,+#
                    : Current line
                     $: Last line
                %: Full text, equivalent to 1,$

/PAT1/: The first time the line is matched to this pattern;
#,/pat1/
/pat1/,/pat2/

After you can follow the edit command:
D, y
W (Save the specified content to another file), R (insert directly)

(2) Find
/pattern: to the tail
? PATTERN: To the header
N: Same direction as command
N: Opposite direction of command

(3) Find and replace
S: In the last line mode, the search and replace operation is done within the bounds of the address;

s/what to look for/replace with content/modifiers
What to look for: Available modes
What to replace: You cannot use a pattern, but you can use a back reference symbol to refer to what the grouping brackets in the preceding pattern match to;
\1, \2, ...
&: Refers to the entire content of the "What to find" matches;
Modifier:
I: Ignore case
G: Global Substitution

/: Used for delimiters, so, to find the content or replace with the content that appears in this symbol, to use \ to escape it, use format: \/
The delimiter can be replaced with other characters: @, #等, for example;

Multi-file Mode:
Vim FILE1 FILE2 ...
: Next: Next file
: First: Go back to file one
:p Rev: Previous File
: Last: Final file

: Wqall: Save exit All Files
: Q!all: Exit All Files

Multi-File Window segmentation:
Vim-o|-o FILE1 FILE2 ...

Ctrl+w, ARROW

Single File Window segmentation:
Ctrl+w, S:split, horizontal split
Ctrl+w, v:vertical, vertical split

Some of the working features of the custom vim:
(1) Line number
Display: Set Nu
Disabled: Set Nonu
(2) Bracket matching
Display: Set SM
Disabled: Set NOSM
(3) Auto indent:
Set AI
Set Noai
(4) Highlight Search
Set Hlsearch
Set Nohlsearch
(5) Syntax coloring
Syntax on
Syntax off
(6) Ignore character case
Set IC
Set Noic

: Help for assistance
: Help SUBJECT

The permanent effect of the feature setting is as follows:
Global configuration file:/ETC/VIMRC
User profile: ~/.VIMRC

Practice:
1, copy the/etc/grub2.cfg configuration file to the/tmp directory, use the Find replacement command to delete the/tmp/grub2.cfg file at the beginning of the blank character;
CentOS:/etc/grub.conf

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/72/C2/ Wkiom1xsdvxzbmrqaaam8-wwvy4396.jpg "" 244 "height="/>

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/72/C2/ Wkiom1xsdvbgdxt-aajmozssgp4687.jpg "" 670 "height=" 331 "/>

2. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # to the beginning of the line beginning with a blank character for each line of/tmp/functions with the find replacement command; The original whitespace character is reserved;

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/72/C2/wKiom1XsdvayAz_ Paaanbjq9k4w555.jpg "" 244 "height="/>

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/72/C2/ Wkiom1xsdvbhlp5daaga7jxc3hg781.jpg "" 669 "height=" 336 "/>

3, replace the/etc/sysconfig/init in/tmp/functions file is/var/log;

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/72/C2/ Wkiom1xsdvbrn1qkaaaeku1aala503.jpg "" 244 "height="/>

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/72/BE/ Wkiol1xser-rpbdfaagxezuxojo557.jpg "" 671 "height=" 337 "/>

4. Delete the beginning of the line in the/tmp/functions file so #, and # followed by at least one blank character #;

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/72/BE/ Wkiol1xser-jjsjeaaaentrpqr4737.jpg "" 242 "height="/>

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/72/C2/ Wkiom1xsdvebqvjkaaeouoqhonm090.jpg "" 668 "height=" 352 "/>

Use of the VIM editor

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.