Introduction to commands, modes, and options for the VI editor

The VI Editor is a command-line-based, powerful text editor originally developed for Unix systems and later ported to many Unix and Linux distributions.

There is another high-level version of VI editor on Linux - VIM (also known as VI IMproved). VIM just adds more features to the already powerful features of the VI. These features are:

Support for more Linux distributions,

Support for multiple programming languages, including code block folding in Python, C++, Perl, etc., syntax highlighting,

Support editing files through various network protocols, including http, ssh, etc.

Support for editing files in compressed archives,

Support split screen to edit multiple files at the same time.

Introduction to commands, modes, and options for the VI editor

Next we will discuss the VI/VIM commands and options. For the purpose of teaching, we use VIs for examples, but all commands can be used for VIM. First let's first introduce the two modes of the VI editor.

Command mode

In command mode, we can perform tasks such as saving files, running commands within VIs, copy/cut/paste operations, and finding/replacement tasks. When we are in insert mode, we can press the Escape (Esc) key to return to the command mode.

Insert mode

In insert mode, we can type in the contents of the file. Press i in command mode to enter insert mode.

Create a file

We can create a file with the following command (LCTT: If the file exists, edit the existing file):

$vi filename

Once the file is created or opened, we first enter command mode, we need to enter the input mode to enter content in the file. We have already roughly understood these two modes through the previous article.

Exit Vi

If you want to exit from insert mode, we first need to press Esc to enter command mode. Next, we can use two commands to exit Vi according to different needs.

Exit without saving – enter :q in command mode!

Save and exit – type :wq in command mode

Moving the cursor

Let's discuss the commands and options for moving the cursor in command mode:

k Move the cursor up one line

j Move the cursor down one line

h Move the cursor one letter to the left

l Move the cursor to the right by one letter. Note: If you want to move multiple lines up or down by one command, or move left or right by multiple letters, you can use 4k or 5j, and the two commands will move up 4 lines. Or move 5 letters to the right.

0 Move the cursor to the beginning of the line

$ Move the cursor to the end of the line

nG moves the cursor to the nth line

G Move the cursor to the last line of the file

{ Move the cursor to the previous paragraph

} Move the cursor to the next paragraph

In addition to this, there are some commands that can be used to control the movement of the cursor, but the commands listed above should be able to handle the daily work.

Edit text

This section will list some commands for command mode, you can enter insert mode to edit the current file.

i insert content at the position of the cursor

I insert the content at the beginning of the line where the cursor is located

a Insert content after the current cursor

A Insert content after the current cursor

o Add a line before the current cursor line

O Add a line after the current cursor line

Delete text

The following commands can only be used in command mode, so you first need to press Esc to enter command mode, if you are in insert mode:

Dd delete the entire line of the cursor, you can add a number before dd, such as 2dd can delete two lines from the cursor line

d$ deletes all lines starting from the line where the cursor is

D^ delete all lines from the beginning of the file until the line where the cursor is located

Dw deletes everything from the cursor position until the next word

Copy and paste

Yy copy the current line, add numbers before yy to copy multiple lines

p Paste the copy line after the cursor

P Paste the copy line before the cursor

The above are some of the basic commands you can use on the VI/VIM editor.

Variable Frequency Drive

Variable Frequency Drive,Variable Frequency Drive For Motor,Three Phase 400V Ac Drive,Variable Frequency Drive For Lift

Zhejiang Kaimin Electric Co., Ltd. , https://www.ckmineinverter.com