Home Operation and Maintenance Linux Operation and Maintenance What is vi/vim? Introduction to the use of vi/vim

What is vi/vim? Introduction to the use of vi/vim

Jul 26, 2017 pm 06:07 PM
usage editor

What is vi/vim?
Almost all configuration files in the Linux world exist in plain text, and there is a vi editor on all Linux distribution systems, so the system can be easily modified using simple text editing software. Various configurations are available, very convenient. Vi is a powerful text editor, and vim is an advanced version of vi. It can not only display text content in different colors, but also perform functions such as shell scripts and C language program editing, and can be used as a program editor.

1. The basic concept of vi
Basically vi can be divided into three states, namely command mode, insert mode and last line mode. The functions of each mode are distinguished as follows:

1) Command mode (command mode)

Control the movement of the screen cursor, delete characters, words or lines, move and copy a section and enter Insert mode down, or go to last line mode.

2) Insert mode

Only in Insert mode, text input can be done. Press the "ESC" key to return to the command line mode.

3) Last line mode

Save the file or exit vi, you can also set the editing environment, such as searching for strings, listing line numbers, etc.

However, generally when we use vi, we simplify vi into two modes, that is, the last line mode (last line mode) is also included in the command line mode (command mode).

2. Basic operations of vi
a) Enter vi

After entering vi and file name at the system prompt, enter the vi full-screen editing screen:

$ vi myfile

Why should we learn vi/vim?
First of all, all Linux distribution systems will have the built-in vi editor by default, and not necessarily other text editors, which is very versatile; secondly, the editing interfaces of many software will call vi by default; thirdly, vi It has the ability to edit programs; finally, the vi program is simple and the editing speed is quite fast.

The three modes of vi and the conversion relationship between each mode

Common operations in general modes

[h (or left arrow key)] Move the cursor one character to the left
[j (or down arrow key)] Move the cursor down one character
[k (or up arrow key) ] Move the cursor up one character
[l (or right arrow key)] Move the cursor one character right

[[Ctrl] + f] Move the screen down one page (equivalent to the Page Down key)
[[Ctrl] + b] Move the screen up one page (equivalent to the Page Up key)

[[0] or [Home]] Move the cursor to the front of the current line
[[ $] or [End]] Move the cursor to the end of the current line

[G] Move the cursor to the last line of the file (the first character)
[nG] n is a number (the same below) , move to the nth line in the current file
[gg] Move to the first line of the file, equivalent to "1G"
[n[Enter]] Move the cursor down n lines

[ /word】 Search for a string with the content of word in the file (search downward)
[?word] Search for a string with the content of word in the file (search upward)
[[n]] Represents repeated search Action, that is, search for the next
[[N]] and reversely search for the next

[x,X] x means to delete one character backward, which is equivalent to [Delete], and X means to delete one character forward. Characters, equivalent to [Backspace]
[dd] Delete the entire line where the cursor is
[ndd] Delete n lines downwards where the cursor is

[yw]: Move the cursor to The characters at the end of the word are copied into the buffer.
[#yw]: Copy # words to the buffer

[yy] Copy the line where the cursor is to the buffer.
[nyy] Copy n lines downward where the cursor is
[p,P] p means to paste the characters in the buffer to the position of the cursor; P means to paste the copied data one line above the cursor

Note: All copy commands related to "y" must be matched with "p" to complete the copy and paste function.

[u] Undo the previous operation
[[Ctrl] + r] Undo multiple times
[.] This is the decimal point key, repeat the previous operation

Operation to switch from general mode to edit mode

1. Enter insert mode (6 commands)
[i] Insert from the current cursor position
[I] From the current position Cursor
[a] Insert
from the next character on the current cursor position [A] Insert from the last character of the line where the cursor is located
[o] English lowercase letter o, at the current cursor position Insert a new line at the next line and start inserting
[O] English capital letter O, insert a new line at the line above the current cursor and start inserting
2. Enter the replacement mode (2 Command)
[r] will only replace the character where the cursor is located once
[R] will always replace the character where the cursor is until the [ESC] key is pressed
[[ESC]] Exit the editing mode Return to normal mode

Switch from normal mode to command line mode
[:w] Save the file
[:w!] If the file is read-only, force save the file
[:q] Leave vi
【:q!】 Force to exit without saving vi
【:wq】 Save and exit
【:wq!】 Force to exit after saving
[:! command] Temporarily leave vi and go to the command line Display result after executing a command
【:set nu】Display line number
【:set nonu】Cancel display of line number
【:w newfile】 Save as

The above is the detailed content of What is vi/vim? Introduction to the use of vi/vim. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Essential software for C language programming: five good helpers recommended for beginners Essential software for C language programming: five good helpers recommended for beginners Feb 20, 2024 pm 08:18 PM

C language is a basic and important programming language. For beginners, it is very important to choose appropriate programming software. There are many different C programming software options on the market, but for beginners, it can be a bit confusing to choose which one is right for you. This article will recommend five C language programming software to beginners to help them get started quickly and improve their programming skills. Dev-C++Dev-C++ is a free and open source integrated development environment (IDE), especially suitable for beginners. It is simple and easy to use, integrating editor,

Analyze the usage and classification of JSP comments Analyze the usage and classification of JSP comments Feb 01, 2024 am 08:01 AM

Classification and Usage Analysis of JSP Comments JSP comments are divided into two types: single-line comments: ending with, only a single line of code can be commented. Multi-line comments: starting with /* and ending with */, you can comment multiple lines of code. Single-line comment example Multi-line comment example/**This is a multi-line comment*Can comment on multiple lines of code*/Usage of JSP comments JSP comments can be used to comment JSP code to make it easier to read

Introduction to Go language development tools: a list of essential tools Introduction to Go language development tools: a list of essential tools Mar 29, 2024 pm 01:06 PM

Title: Introduction to Go language development tools: List of essential tools In the development process of Go language, using appropriate development tools can improve development efficiency and code quality. This article will introduce several essential tools commonly used in Go language development, and attach specific code examples to allow readers to understand their usage and functions more intuitively. 1.VisualStudioCodeVisualStudioCode is a lightweight and powerful cross-platform development tool with rich plug-ins and functions.

How to correctly use the exit function in C language How to correctly use the exit function in C language Feb 18, 2024 pm 03:40 PM

How to use the exit function in C language requires specific code examples. In C language, we often need to terminate the execution of the program early in the program, or exit the program under certain conditions. C language provides the exit() function to implement this function. This article will introduce the usage of exit() function and provide corresponding code examples. The exit() function is a standard library function in C language and is included in the header file. Its function is to terminate the execution of the program, and can take an integer

Usage of WPSdatedif function Usage of WPSdatedif function Feb 20, 2024 pm 10:27 PM

WPS is a commonly used office software suite, and the WPS table function is widely used for data processing and calculations. In the WPS table, there is a very useful function, the DATEDIF function, which is used to calculate the time difference between two dates. The DATEDIF function is the abbreviation of the English word DateDifference. Its syntax is as follows: DATEDIF(start_date,end_date,unit) where start_date represents the starting date.

Golang editor recommendations: five choices suitable for development Golang editor recommendations: five choices suitable for development Jan 19, 2024 am 09:00 AM

With the popularity and popularity of Golang, more and more developers are beginning to use this programming language. However, like other popular programming languages, Golang development requires choosing a suitable editor to improve development efficiency. In this article, we will introduce five editors suitable for Golang development. VisualStudioCodeVisualStudioCode (VSCode for short) is a free cross-platform editor developed by Microsoft. It is based on Elect

Introduction to Python functions: Usage and examples of isinstance function Introduction to Python functions: Usage and examples of isinstance function Nov 04, 2023 pm 03:15 PM

Introduction to Python functions: Usage and examples of the isinstance function Python is a powerful programming language that provides many built-in functions to make programming more convenient and efficient. One of the very useful built-in functions is the isinstance() function. This article will introduce the usage and examples of the isinstance function and provide specific code examples. The isinstance() function is used to determine whether an object is an instance of a specified class or type. The syntax of this function is as follows

Detailed explanation and usage introduction of MySQL ISNULL function Detailed explanation and usage introduction of MySQL ISNULL function Mar 01, 2024 pm 05:24 PM

The ISNULL() function in MySQL is a function used to determine whether a specified expression or column is NULL. It returns a Boolean value, 1 if the expression is NULL, 0 otherwise. The ISNULL() function can be used in the SELECT statement or for conditional judgment in the WHERE clause. 1. The basic syntax of the ISNULL() function: ISNULL(expression) where expression is the expression to determine whether it is NULL or

See all articles