Home  >  Article  >  Operation and Maintenance  >  Vim editor mode from getting started to giving up

Vim editor mode from getting started to giving up

齐天大圣
齐天大圣Original
2020-06-09 15:20:352565browse

The vim editor has the title of God of Editors. However, because it is extremely difficult to get started, many programmers go through the process from getting started to giving up. I also gave up twice, and then slowly and gradually mastered it. Do the math, I am also a vim worker with 2 years of experience.

Different from general editors, after vim is opened, it defaults to normal mode, and text cannot be edited at this time. Closing this step will dissuade many users. Because beginners find out why they can't edit files, and then they think to themselves that it is called the best editor in the universe, but it is really a garbage editor! In addition, it cannot use the mouse, and cannot select text and other operations through the mouse. These two points will probably scare off most beginners!

First of all, let’s talk about what vim mode is. There are three vim modes (some tutorials say four, and block selection is also regarded as a mode), which are normal mode, insert mode and command line mode. Below, I will make a diagram to illustrate the relationship between the three:

Vim editor mode from getting started to giving up

Enter editing mode

When we enter the vim editor, it defaults to normal mode. At this time, if you want to enter some characters, you need to go to insert mode first. To enter insert mode, you can directly press the following letters. Their meanings are different:

  • a inserts after the cursor

  • A in the current Insert

  • at the end of the line. Insert

  • before the cursor. I Insert

  • at the beginning of the current line. oInsert a new line below

  • OInsert a new line above

After entering insert mode, you can freely edit text . If you want to return to normal mode, just press the esc key.

Save and exit

Regarding the command line mode, today we will only talk about the text save and exit operations, leaving other operations such as search and replacement for later. Talk again. Common save and exit commands are as follows:

  • :w save file

  • :wq save and exit

  • :q Exit

  • :q! Force exit without saving the file

  • :w filename Save as

Execute shell commands

There is a very practical technique in vim command line mode, which is often used when writing shell scripts. The syntax of the command is as follows:

:! [command]

There are two methods to return to the normal mode from the command line mode. The first is to delete the command on the command line, and the other is to press the esc key twice in succession.

Of course, I am not here to persuade everyone to give up learning vim, but I hope that more people will join in the use of this editor. Here are two suggestions for learning vim:

  • Use hjkl to replace the up, down, left and right keys

  • Practice more, and the more you practice, the better. Develop your own muscle memory

The above is the detailed content of Vim editor mode from getting started to giving up. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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