Summary of the use of the Vi/vim editor

Source: Internet
Author: User
Tags arithmetic

Vi/vim Editor

Open File:

#vi [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;


(1) Mode conversion:

Edit mode: Default mode

Edit mode---> Output mode:

I:insert, enter at the cursor position

A:append, after the cursor is in place input

O: Opens a new line below the cursor position

I: Enter at the beginning of the cursor

A: Enter at the end of the line where the cursor is located

O: Opens a new line at the top of the cursor position


Input mode----> Edit mode

Esc

Edit mode-------> last-line mode

:

Last-line mode-------> Edit mode

Esc


(2) Close the file:

ZZ: Save and exit


End-of-line mode exit

: Q file does not change direct exit

: q! Force exit, do not save the previous edit operation

: Wq Save changes and exit


(3) Cursor jump operation

A, inter-character jump

H: Jumps one character to the left

L: Jump Right One character

J: Jump down one character

K: Jumps up one character


B, Word jump

W: Jump to the beginning of the next word

B: Jump to the beginning of the current or previous word

E: The ending of the current or last word


C, beginning line end jump

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

0: Jump to the beginning of the line

$: Jump to absolute end of line


D. Jump between rows

#G: Jump to the line specified by #, if jump to the beginning of the first line of the file header, 1G, jump to the end of the file (the last part of the beginning), G


E, inter-sentence jump

F, inter-paragraph jump

}

{

Screenshot:

CTRL+F: Flip a screen to the end of the file

CTRL+B: Flip a screen to the file header

Ctrl+d: Turn half screen at the end of the file

Ctrl+u: Turn half screen to file header

Enter: Turn back directly


Vim Edit command:

Character editing:

X: Delete the character at the cursor location

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

XP: Swap the position of the character at the cursor and the character behind it


Replace command (replace):

R: the character at which the cursor is replaced

Rchar

Delete command:

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

d$: Jump to end of line

DW: Delete one character

De

Db:

DD: Delete the line where the cursor is located

Paste command:

P: The contents of the buffer are pasted at the bottom of the line where the current cursor is, if the entire row is the same, otherwise, it is pasted at the back of the current cursor

P: The contents of the buffer are pasted at the top of the line where the current cursor is, if the entire row is the same, otherwise, paste to the front of the current cursor


Other editing operations:


Visualization mode:

V: Selected by character

V: Selected by row

Combined with editing commands, d,c,y



Undo (undo) Action:

U: Undo Previous Action

#u: Undo the previous undo operation


Repeat the previous edit operation:

.


Vim last-line mode:

Built-in command-line interface

(1) Address delimitation

: Start_pos[,end_pos]

#: A specific line of #, for example, 5 is the 5th line;

.: Current line,. +3 Current line 3 rows to the right

$: Last line

., $-1: Indicates the line from the current line to the bottom 2nd row

1,$: Indicates from line 1th to the last line, that is, the full text

%: also expressed in full

#,#: Specifies the row range, the left is the starting line, the right side is the end line;

#,+#: Specifies the row range, the left side is the initial row absolute number, the right side is the relative left line number offset; For example: 3,+7

/pattern/: Represents the first line that matches the pattern to the end of the file from the beginning of the cursor position;

/first/,$: Indicates the first match to the last line

/PART1/,/PART2/: From the beginning of the cursor, the first time there is a line that matches part1 to all rows between the end of the first line matched by Part2

These delimiters are used in combination with the edit command to achieve the editing operation:

D

Y

C

W/path/to/soomefile: Saves the text in the range to the specified file;

Note here: The first thing to do is to select what you want to save and then enter the above command, especially if you save some of the content in the file.

R/path/from/somefile: Reads and inserts text from the specified file into the specified location for file two file merge

In general mode, the contents of the hostname.sh script are added to the current file:

r/root/hostname.sh


(2) Find

/pattern: Finds all strings that can be matched to the current pattern from the current cursor location to the end of the file

? Pattern: finds all strings that can be matched to the current pattern from the current cursor position to the file header

N: Next, same as command direction

N: Previous, opposite of command direction


(3) Find and replace

S: command of the last-line mode, use format

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


What to look for: You can use regular expressions

Replace with: cannot use regular expression, but can reference;

If the "What to find" section uses a grouping symbol in the pattern, use a back reference in "Replace with";

The entire text that the lookup pattern matches directly;

Modifier:

I: ignoring case;

G: Global substitution means that if a row is matched to multiple times, it is replaced:

You can replace separators with other non-common characters:

[Email protected]@@

s###


Vim's multi-file feature:

Multiple files

Vim file1 file2 ...

To switch between files:

: Next Next

:p Rev Previous

: First One

: Last One

Exit All Files:

: Wqall Save all files and exit

: All Save All Files

: Qall Exit All Files

Multiple windows:

-O: Horizontal split window

-O: Vertical Split window


Switching between windows: Ctrl+w,arrow

Note: Individual files can also be split into multiple windows for viewing

Ctrl+w,s: Water Split window

Ctrl+w,v: Vertical Split window



Customizing the working characteristics of vim:

Note: The settings in the last line mode are only valid for the current VIM process;

Permanently valid:

Global:/ETC/VIMRC

User personal: ~/.VIMRC

1, line number

Display: Set number, abbreviated as set Nu

Cancel display: Set Nomber,set Nonu

2. Bracket matching highlighting

Match: Set Shownmatch, set SM

Cancel: Set Noshowmatch,nosm


3. Auto Indent

Enable: Set AI

Disabled: Setnoai

4. Highlight Search

Enabled: Set Hlsearch

Disabled: Set Nohlsearch

5. Syntax highlighting

Enabled: Syntax on

Forbidden: Syntax off

6. Ignore character case

Enable: Set IC

Disabled: Set Noic


Get help:

: Help

: Help Subject


The arithmetic operation of bash script programming

+,-,*,,, **,%

Arithmetic operation format:

(1) Let var= arithmetic operation expression

(2) var=$[arithmetic expression]

(3) var=$ (arithmetic operation expression)

(4) var = $ (Expr $ARG 1 $OP $ARG 2)


Note: The multiplication symbol needs to use escape characters in some scenarios


This article from "Flat Light is true" blog, please be sure to keep this source http://ucode.blog.51cto.com/10837891/1896775

Summary of the use of the Vi/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.