Vi editor notes, vi Editor

Source: Internet
Author: User

Vi editor notes, vi Editor

Abstract:

Vi Installation and Use

Vi from cainiao to master

0. vim-Vi IMproved, a programmers text editor

It can be divided into VI and VIM. In popular releases, VI = VIM

Is a text editor (all text without images, plain text content, without the suffix)

The binary file cannot be edited.

The directory cannot be edited.

When installing vim In the Debian system:

Apt install vim

 

1. Currently, there is only one place on the earth and vi is not installed by default.

Docker image Images container

2. view the VI version.

On the command line: "vi -- version"

In the text: ": version"

3. Procedure

1. vi filename

Vi is followed by a file name // if it exists, open the editing directly. If it does not exist, create a new file

2. Enter the insert mode.

Type the "I" key. We recommend that you press the I key.

You can also type the "s" key, but the s key is to delete the character of the current cursor and then enter the insert mode.

3. insert data

4. Press the "Esc" key, or type the combination key "^ [" (Ctrl-[) to enter the command mode.

TIPS: When you press the combination key, you must first press the front secondary key, and then press the function key

5. Enter ":", and then type "x/wq/w/q! /Q/qa! "

Command

Description

Status

X

Save and exit

 

Wq

Save and exit

 

W

Save

Written

Q!

Force exit and not save

 

Qa!

It is equivalent to q!

 

Q

Exit

 

Qa

Equivalent to q

 

Quick exit:

^ W q // Ctrl + w q

It is equivalent to q.

4. Status line

The last row of the current editing window is called a status row.

Used to display file names

Show rows and columns

Number of characters displayed

5. Three Modes

Insert mode

I

Enter insert mode

Command mode

^ [Or Esc

Enter command mode

Last Row Mode

:

Enter the last line

 

Insert mode

I

Insert data at the current location

A

Insert data behind the cursor position

A

Insert data at the end of the row

O

Insert data in the next row of the row where the cursor is located

O

Insert data in the last row of the row where the cursor is located

S

Delete the character at the cursor position and insert data after the cursor

S

Delete the row where the cursor is located and insert data at the beginning of the row

Cw

Delete the word with the current cursor and enter insert mode

6. move the cursor in the file

Up to down

H

Bytes

L

J

Bytes

K

Bytes

End of the first line

^

The beginning of the line. It is a non-null character and does not contain spaces.

0

The beginning of the line, with a space

$

The end of the line. It contains spaces and null characters.

G _

The end of the line. It is a non-null character and does not contain spaces.

Beginning and end

Gg

Preface

G (shift + g)

End

 

Middle bottom of screen head

H (shift + h)

Top Line

M (shift + m)

Intermediate line

L (shift + l)

Bottom Line

Screen flip

^ F

Flip down

^ B

Forget to flip the screen

 

Undo

U

Undo one operation

1 change; before #19 22 seconds ago

^ R

Undo an operation

1 change; after #19 33 seconds ago

Delete

X

Delete A character at the cursor

Dw

Deletes a word from the cursor.

D (shift + d)

Delete all characters behind the cursor

Dd

Delete current row

Ndd

Delete N rows

Dw

Delete a word

Copy and paste

Yy

Copy a row

P

Paste

V-w-y

Copy a word

V-y

Copy one character

 

7. Search for a string

Enter "/" to enter the search mode, and then enter the string to be searched.

N

Jump to the next string

N

Jump to the previous string

8. Replacement

: S/old/new

Replace the first old with new in a row

: S/old/new/g

Replace all old with new in a row

: S/old/new/gc

Replace all old with new in a row.

: % S/old/new/g

Replace all old with new in the file

: % S/old/new/gc

Replace all old with new in the file.

TIPS: In ":" mode, type "^ p/^ n" or "Quit/quit" to select the command that has been executed.

9. Simple settings

In ":" Mode

Row number

Set nu (number)

Set nonu

Read-Only

Set readonly

Indent

Set paste

 

10. Classification

Level

Lifecycle

Requirements

Remarks

Level 1

Can Eat

Install

Start

View document

Know the common operations after entering

Up to down

Delete

Copy

Paste

Insert

Exit

 

Level 2

Eat meat

You will

Move the cursor

Copy and paste the picker

You cannot cancel the operation.

Entrance and exit to the free redcard Building

 

Level 3

Delicious and spicy

Better

Various duplicates

Stronger

Various hops

Faster

Flying everywhere

 

Level 4

Paid

Cheng Shen

 

11. Expansion

1. Automatic prompt

^ P

Call up the automatic Prompt window and operate one row up

^ N

Call up the automatic Prompt window and operate on the next line

^ M

Confirm

2. Block operations

^ V

Block operation

Add ##

^ V

-> Shift-I

-> ##

-> ^ [

3. Visual Selection

V

Go to visualization Selection

V

Select a row

4. indent

<

Left indent

>

Right indent

5. Split screen

^ W s/: sp

Split landscape Screen

^ W v/:

Split portrait Screen

^ W q

Exit

^ W hjkl

Switching between screens

 

6. Create a new file

In the command mode of vi, after the ":" command is used in the currently opened file,

Type: new file_name to create a new file_name file window in the current window.

In this case, you can switch up and down through ^ w jklm or copy and paste multiple files freely.

7. Other advanced tips

1. Save changes to files that do not have permissions (use ": w! Sudo tee % "):

Your @ your:/etc/apt $ vi 1111

After inserting data, type the command mode I (":")

Operation:

": W! Sudo tee %"

-> Press "O" or "L ".

: R! Uname-a // Insert the content displayed after the command is executed to this text

: W! Sudo tee %

// Raise the permission and save the edited document

Execution Process:

Linux your 4.4.0-87-generic # 110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

 

W13: Warning: File "11111" has been created after editing started

[O] K, (L) oad File:

 

: W! Sudo tee %

 

Linux your 4.4.0-87-generic # 110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

 

W13: Warning: File "11111" has been created after editing started

 

Press ENTER or type command to continue

Your @ your:/etc/apt $ cat 11111

 

Linux your 4.4.0-87-generic # 110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Your @ your:/etc/apt $

2. Edit vi in lock screen mode

^ S

Lock screen, terminate screen terminal ECHO

^ Q

Restore normal mode

Note: If you are not familiar with the keyboard, that is to say, the typing speed is lower than 150, or the error rate is higher than 1%, we recommend that you do not touch these highly risky operations, otherwise you will be at your own risk.

3. Other supplements:

1. Summary of highlight in vi configuration file and search mode:

Configuration file:

Your @ your :~ $ Cd

Your @ your :~ $ Ll. vimrc

-Rw-r -- 1 your 31 Aug 7 04:13. vimrc

. File_name

"." Indicates hiding files in linux.

You can use ls-a to view hidden files.

-A, -- all

Do not ignore entries starting.

You can change the vi display in two modes:

Temporary

In the file

Permanent

In the. vimrc configuration file

 

Type the syntax that complies with vi

Highlight the search mode:

Permanent:

1. vi. vimrc

2. set hlsearch

Temporary:

1. vi file_name

2.: set hlsearch

Permanent:

1. vi. vimrc

2. Delete set hlsearch or comment

Note: In the configuration file of. vimrc, "Double quotation marks indicate annotations.

A syntax highlighting demo that enables line number display and search highlighting:

2. instructions before and after vi search mode:

/

Backward Search

N: Next

N: Previous

?

Forward search

N: Previous

N: Next

 

Forward <---- "N "----"? "--" N "--- souce ----" N "---"/"-----" n "---> backward

 

 

3. Run the linux Command in vi and mysql:

Environment

Method

Description

Vi

:! Linux_command

Create a new window to execute commands

Mysql

\! Linux_command

Or

System linux_command

Execute commands on the current mysql interactive interface

Note :\! There is a space between it and the command, otherwise:

Mysql> \! Pwd

ERROR:

Usage :\! Shell-command

Mysql> \! Pwd;

/Home/huhua

Mysql>

System (\!) Execute a system shell command.

 

4. Advanced features: Use the SSH service to log on to a remote host:

Mysql

System ssh core@192.168.28.144

Vi

! Ssh core@192.168.28.144

5. vi Insert ":" the output of the mode execution command is in the current vi text.

: R! Linux_command

Both ping and ping can be imported into the text, but the ping output is not clear.

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.