linux-Basics-Day 12th

Source: Internet
Author: User

Vim Editor


Brief introduction

Vi:visual Interface, Text editor


Text: ASCII, Unicode


Type of text editing:

Line Editor: SED

Full Screen Editor: Nano, VI


Vim-vi improved


Use

Vim: A patterned editor


Basic mode:

Edit mode, Command mode

Input mode

Last-line mode: Built-in command-line interface


Open File:

# vim [OPTION] ... FILE ...

+#: After opening the file, the cursor is directly at the beginning of line #;

+/pattern: After opening the file, the cursor is directly at the beginning of the first line that is matched to the PATTERN;


Mode conversion:

Edit mode--Input mode

I:insert, enter at the cursor position;

A:append, enter at the back of the cursor position;

O: Opens a new line below the line where the cursor is currently located;

I: Enter at the beginning of the line where the cursor is currently located;

A: Enter at the end of the line at the current cursor;

O: Opens a new line above the line where the cursor is currently located;

C

C


Input mode--edit mode

Esc


Edit Mode--last-line mode

:


Last-line mode--edit mode

Esc


To close a file:

: Q exit

: q! Force exit, discard the changes made;

: Wq Save Exit

: X Save exit

: W/path/to/somewhere


ZZ: Save exit;


Cursor Jump:

Jump between characters:

H, J, K, L

H: Left

L: Right

J: Next

K: Up


#COMMAND: Jumps the number of characters specified by #;


Jump between words:

W: The first word of the next word

E: The ending of the current or next word

B: The first word of the current or previous word


#COMMAND: Specifies the number of words to jump by # at one time


Beginning line End Jump:

^: jumps to the first non-whitespace character at the beginning of a line;

0: Jump to the beginning of the line;

$: Jump to end of line;


Move between rows:

#G: Jumps to the line specified by #;

G: Last line;

1G, GG: First line;


Move between sentences:

)

(


Move between paragraphs:

}

{


Vim's edit command:


Character editing:

X: Delete the character at the cursor;

#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 behind it;


Replace command (R, replace)

R: the character at which the cursor is replaced


Delete command:

D: Delete command, can be combined with the cursor jump character, to achieve range deletion;

d$:

d^:

D0:


Dw

De

Db


#COMMAND


DD: Delete the line where the cursor is located;

#dd: Multi-line deletion;


Paste command (p, put, paste):

P: If the buffer is an entire row, the current cursor is pasted below the line, otherwise, it will be pasted at the back of the current cursor;

P: If the buffer is an entire row, the current cursor is pasted above the row, otherwise, it is pasted at the front of the current cursor;


Copy command (y, yank):

Y: Copy, work behaves similar to D command;

y$

Y0

y^


Ye

yw

Yb


#COMMAND


YY: Copying rows

#yy: Copy multiple lines;


changing commands (c, change)

C: Modify

Edit mode--Input mode


C $

c^

C0


Cb

Ce

cw

#COMMAND


CC: Delete and enter new content

#cc:


Other editing operations


Visualization mode:

V: Selected by character

V: set by row


Note: often combine editing commands;

D, c, y


To undo previous edits:

U (undo): Undo the previous operation;

#u: Undoes the specified number of operations;


Undo the previous undo:

Ctrl+r


Repeat the previous edit operation:

.


Turn screen operation:

Ctrl+f: Turn a screen at the end of the file;

Ctrl+b: Turn one screen to the file header;


Ctrl+d: Half-screen to the tail of the file;

Ctrl+u: Turn half screen to file header;


Vim comes with a practice tutorial:

Vimtutor


Last-line mode in VIM:

Built-in command-line interface


(1) Address delimitation

: Start_pos,end_pos

#: The specific # line, for example, 2 means line 2nd;

#,#: From the left # indicates the line start, to the right # indicates the end of the line;

#,+#: The start of the line from the left #, plus the number of rows on the right #;

.: When moving forward

$: Last line

., $-1

%: Full text, equivalent to 1,$


/pat1/,/pat2/:

Starting from the first line that is matched to the pat1 pattern, until the end of the line to which the first match is PAT2;

#,/pat/

/pat/,$


How to use:

followed by an edit command

D

Y

W/path/to/somewhere: Save the range of rows to the specified file;

R/path/from/somefile: Inserts all the contents of the specified file at the specified location;


(2) Find

/pattern: Looks at the end of the file from the current cursor location;

? PATTERN: From the current cursor location to the file header lookup;

N: In the same direction as the command;

N: Opposite direction with command;


(3) Find and replace

S: Complete the Find and replace operation in the last line mode

s/what to look for/replace with content/modifiers

What to look for: Available modes

Replace with: cannot use mode, but can use \1, \2, ... You can also use "&" to refer to the entire content found in the previous lookup;

Modifier:

I: Ignore case

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


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

[Email protected]@@

s###


linux-Basics-Day 12th

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.