(Big Data Engineer Learning Path) Step two vim editor----VIM QuickStart

Source: Internet
Author: User

Introduction to VIM Mode

The following introductory content is from the Wikipedia vim

There are many modes of vim from VI, this unique design is easy to confuse the beginner. Almost all editors have two modes of inserting and executing commands, and most editors use a different approach to vim: the command directory (mouse or keyboard driver), the combination of keys (usually with the control key (CTRL) and the ALT key (ALT)) or the mouse input. Vim and VI, just as the keyboard to switch among these modes. This allows vim to operate without a menu or mouse, and to minimize the operation of key combinations. It can greatly enhance the speed and efficiency of the text entry clerk or programmer.

VIM has 6 basic modes and 5 derivation modes, and here we simply introduce the next 6 basic modes:

    • Normal mode

In normal mode, the editor commands, such as moving the cursor, deleting text, and so on. This is also the default mode after Vim is started. This is exactly the opposite of what many new users expect (most editor default mode is insert mode).

Vim's powerful editor can come from its normal mode commands. Normal mode commands often require an operator end. For example, the normal mode command dd deletes the current row, but the first "D" can be followed by another move command instead of the second one d , such as a "J" key that moves to the next line to delete the current row and the next row. You can also specify the number of commands to repeat, 2dd (repeat dd two times), and dj the effect is the same. Users learn a variety of text between the move/jump commands and other common mode of editing commands, and can be used flexibly combined, can be more efficient than those without the pattern of the editor for text editing.

In normal mode, there are many ways to get into insert mode. The more common way is to press a (append/append) or i (insert/insert) key.

    • Insertion modes (insert mode)

In this mode, most keystrokes insert text into the text buffer. Most new users want this mode to persist throughout the text editor editing process.

In insert mode, you can press the ESC key back to normal mode.

    • Visual modes (visual mode)

This pattern is similar to normal mode. However, the move command expands the highlighted text area. The highlighted area can be a character, a line, or a piece of text. When a non-moving command is executed, the command is executed to the highlighted area. Vim's "text object" can also be used in this mode as the move command.

    • Selection mode (select modes)

This pattern is similar to the behavior of the modeless editor (the way Windows standard text controls are). In this mode, you can use the mouse or cursor keys to highlight the selection of text, but the input of any character, Vim will use this character to replace the selected highlighted text block, and automatically enter the insertion mode.

    • Command line mode

In command-line mode, you can enter text that will be interpreted and executed. For example, execute commands ( : keys), search ( / and ? keys), or filter commands ( ! keys). After the command is executed, VIM returns to the pattern before the command-line mode, usually in normal mode.

    • Ex modes (ex mode)

This is similar to command-line mode, where :visual you can execute multiple commands at one time before using the command to leave the ex mode.

This is commonly used in common mode, insert mode, and command line mode, and this course covers only the three common patterns.

2. Switching of three common modes

Vim starts into normal mode, in insert mode or command line mode, just press Esc or Ctrl+[ (this is no use in the VIM course environment) to enter normal mode. In normal mode i , press (insert) or a (attach) keys to enter the insert mode, in normal mode press : enter command line mode. In the command line mode, enter the wq carriage return and save and exit Vim.

Third, enter the VIM1. Use the VIM command to enter the Vim interface

Vim is appended with the file name that you want to open, or that does not exist (then as a new file). Open the Xfce terminal and enter the following command

$ vim practice_1.txt

Vim editor can also be opened using Vim directly, but no files will be opened.

$ vim

Enter the command line mode and the :e 文件路径 same file can be opened.

2. Cursor movement

After entering Vim, press the i key to enter insert mode. In this mode you can enter text information below, please enter the following three lines of information:

12345678abcdefghijkshiyanlou.com

Press Esc Enter normal mode, use the arrow keys in this mode or,,, the h j k l Key can move the cursor.

Key Description
h Left
l Right (lowercase L)
j Under
k On
w Move to the next word
b Move to the previous word

Try using the arrow keys to move the cursor over these letters in normal mode shiyanlou .

Iv. Enter insert mode 1. Enter insert mode

Use the following key in normal mode to enter insert mode, and to start typing from the corresponding position

Command Description
i Edit at current cursor
I Insert at beginning of line
A Inserting at the end of a row
a Insert an edit after the cursor
o Insert a new row after the current row
O Insert a new row before the current line
cw Replace the character from the position of the cursor to the end of a word

Try different ways to get into the insert mode from normal mode, add in front of the last line Shiyanlou www. , Notice that each time you go back to normal mode to switch to insert mode in different ways

V. Save a Document 1. Save the document in command line mode

Enter the : command line mode from normal mode, enter w a carriage return, and save the document. Enter to save the :w 文件名 document as a different file name or save it to another path

Vi. exit vim1. Exit vim in command line mode

Enter : command line mode from normal mode, enter wq return, save and exit edit

Here are a few other ways to exit:

Command Description
:q! Force quit, do not save
:q Exit
:wq! Force Save and exit
:w <文件路径> Save As
:saveas 文件路径 Save As
:x Save and exit
:wq Save and exit
2. Exiting vim in normal mode

Normal mode input Shift+zz can be saved out of vim

Vii. deletion of text 1. Delete vim text information in normal mode

Go to normal mode and use the following commands to quickly delete text:

Command Description
x Delete the character that the cursor contains
X Delete the previous character of a cursor
Delete Withx
dd Delete entire row
dw Delete a word (not in Chinese)
d$OrD Delete to end of line
d^ Delete to beginning of line
dG Delete to end of document
d1G Delete to document header

In addition, you can add a number to the command before it, indicating that multiple rows are deleted at once, such as:

2ddRepresents deleting 2 rows at a time

Let's do the following exercises:

$ cp /etc/protocols .$ vim protocols

Viii. Summary

Vim first experience you feel very strange, perhaps at present you do not have vim to produce any favor, do not think it is a good editor, it can only be because you have not mastered the essence of vim, or you type too slow, go back to the Little Overlord learning machine to practice it-_-| | Here can also be revealed, the essence of vim is the command key combination, the operation of the whole keyboard, you can not leave the keyboard input area to complete all the operation, that can be real efficient and cool experience ah, when you master this skill can definitely seconds off other not with VIM programmer several street (at least in the momentum bar, And of course to get rid of the only Emacs programmers, because there is a war between Emacs and Vim, it is interesting to see Emacs and Vim here: God's editor and editor of God)

Nine, thinking practice

Why Vim uses such wonderful directional keys, and h j k l So awkward anti-human Esc as the key to exit the insert mode. Give a hint: you can understand the goods adm-3a

(Big Data Engineer Learning Path) Step two vim editor----VIM QuickStart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.