The difference between VI and vim and the detailed explanation of command

Time:2021-3-5

VI has three modes: insert mode, command mode and low line mode.

Insert mode:In this mode, you can enter characters and press ESC to return to command mode.

Command mode:You can move the cursor, delete characters, etc.

Low row mode:It can save files, exit VI, set VI, search and other functions (low line mode can also be regarded as command mode).

1、 Open, save and close the file (used in VI command mode)

VI file name / / open the file name
: w / / save the file
:w vpser.net //Save to vpser.net file
: Q / / exit the editor. If the file has been modified, use the following command
: q! / / exit the editor without saving
: WQ / / exit the editor and save the file

2、 Insert text or line (used in VI command mode, after executing the following command, it will enter the insert mode, press ESC key to exit the insert mode)

A / / add text to the right of the current cursor position
I / / add text to the left of the current cursor position
A / / add text at the end of the current line
I / / add text at the beginning of the current line (the beginning of a non empty character)
O / / create a new line above the current line
O / / create a new line below the current line
R / / replace (overlay) the current cursor position and the following text
J / / merge the cursor line and the next line (still in command mode)

3、 Move cursor (used in VI command mode)

1. Use the up, down, left and right arrow keys

2. Command mode: H ﹣ left, J ﹣ down, K ﹣ up, l ﹣ right.

The space bar moves to the right, backspace to the left, enter to the beginning of the next line, and – to the beginning of the previous line.

4、 Delete and restore characters or lines (used in VI command mode)

X / / delete the current character
Nx / / delete n characters from the cursor
DD / / delete the current line
NDD / / delete n rows including the current row
U / / undo the previous operation
U / / undo all operations on the current line

5、 Search (used in VI command mode)

/Vpser / / search the cursor for the vpser string
? vpser / / searches the cursor for the vpser string
N / / search down the previous search action
N / / search up for the previous search action

6、 Jump to the specified line (used in VI command mode)

N + / / jump n lines down
N – / / jump up n lines
Ng / / jump to line n
G / / jump to the bottom of the file

7、 Set line number (used in VI command mode)

: set / / nu / / displays the line number
: set nonu / / suppresses the display of line numbers

8、 Copy and paste (used in VI command mode)

YY / / copy the current line to the cache. You can also use “Ayy copy.” a is the buffer. A can also be replaced by any letter from a to Z. multiple copy tasks can be completed.

NYY / / copy the current line to the buffer. You can also use “anyy copy.” a is the buffer. A can also be replaced by any letter from a to Z. multiple copy tasks can be completed.

YW / / copies the characters from the beginning of the cursor to the end of the word.

NYW / / copies n words starting from the cursor.

Y ^ / / copies the content from the cursor to the beginning of the line. VPS detective

Y $/ / copy the content from the cursor to the end of the line.

P / / paste the contents of the clipboard after the cursor. If the previous custom buffer is used, it is recommended to use “AP” to paste.

P / / the contents in the paste clipboard are in front of the cursor. If the previous custom buffer is used, it is recommended to use “AP” to paste.

9、 Replacement (used in VI command mode)

: S / old / new / / replace the first old in the line with new
: S / old / new / g / / replace all old in the line with new
: n, M S / old / new / g / / replace all old lines from n to m with new
:% s / old / new / g / / replace all old files in the current file with new

10、 Edit other files

: e otherfilename / / edit the file named otherfilename.

11、 Modify file format

: set fileformat = UNIX / / modify the file to UNIX format. For example, the text file under win will appear ^ m under Linux.

This article about the difference between VI and vim and the detailed explanation of commands is the whole content shared by Xiaobian. I hope it can give you a reference, and I hope you can support developer more.

Recommended Today

Rust and python: why rust can replace Python

In this guide, we compare the rust and python programming languages. We will discuss the applicable use cases in each case, review the advantages and disadvantages of using rust and python, and explain why rust might replace python. I will introduce the following: What is rust? What is Python? When to use rust When to […]