Introduction to Vim’s three modes and some common commands


Because I recently realized how efficient and powerful Vim is as a text editing tool, I can even edit text at the speed of thinking. However, because there are too many details, I opened a column to help myself record and learn Vim.
In addition, let’s briefly introduce the difference between vi and vim. VIM is an upgraded version of vi. In addition to being compatible with all instructions of vi, VIM also has some new features (multi-level undo, ease of use , syntax highlighting, visual operations, etc.)
If you want to use VIM under win system, you can refer to Windows 11 Installation Vim Editor Configuration Guide

1. Normal mode/command mode (command mode)

When you start vim, you will enter the command mode by default, where you can move the cursor, copy and paste, delete characters, etc.
(This is the most powerful mode and the most commonly used mode)i (switch to insert mode), x (delete the character currently under the cursor), :( Switch to command line mode) < /font>.
In this state, keyboard input will be recognized as a command operation. Commonly used ones include

2. Input mode

In normal mode, press the keyboard [i, I, o, O, a, A] to enter the insert mode. The words [–INSERT–] will appear in the lower left corner of the screen, indicating that in the current mode, the user can edit and modify the content of the text. . Press [Esc] to exit editing mode.

3. Last line mode/command mode (last line mode)

In normal mode, press any one of the keyboard [: / ?], the cursor moves to the bottom line, and enters the last line mode. You can find data, replace, save files, exit vi, display line numbers and other operations.
A simple diagram of the switching methods among the three

4. Common instructions in last line mode

Order describe
i Enter insert mode and insert text before the cursor
a Enter insert mode and insert text after the cursor
O Insert a new line under the cursor and enter insert mode
O Inserts a new line above the cursor and enters insert mode
Esc 或 Ctrl + [ Exit insert mode and return to normal mode
:In Save current file
:wq or :x or ZZ Save and exit
:q Exit current file
:q! Force quit the current file without saving
:set number Show line number
:set nonumber Do not display line numbers
:set syntax=<Language> Set syntax highlighting
:set nosyntax Turn off syntax highlighting
:e <file name> Open specified file
:split or :sp split window
:vsplit or :vsp Split window vertically
:tabnew or :tabe New tab
:tabnext or :tabn Next tab
:tabprevious or :tabp Previous tab
:tabclose or :tabc Close tab
:set list Show invisible characters
:set nolist Do not display invisible characters
:set expandtab Convert Tab to space
:set noexpandtab Don't convert Tabs to spaces
:set tabstop=<Number> Set the width of the Tab
:set shiftwidth=<Number> Set the width of automatic indentation

Guess you like

Origin blog.csdn.net/m0_71417856/article/details/130478652