Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic use of Vim editor and methods of multi-line indentation

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "the basic use of the Vim editor and the method of multi-line indentation". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Basic use of vim

Type the vim command and the name of the file to be edited in the terminal to launch the vim editor (if the file name is not specified when starting vim, or the file does not exist, vim will open a new buffer area for editing).

The vim editor has two modes of operation:

Ordinary mode

Insert mode

Just started the vim editor, enter the normal mode by default, in this mode, the vim editor will interpret the keys as commands (this is also the special feature of vim, many people who have not used vim will be intimidated by this mode when they start to open vim, after all, it is rare to press keys on the keyboard but do not react at all to the editor).

Type I in normal mode to enter insert mode (insert. In fact, typing an or I can also enter insert mode, where vim inserts every key you enter at the cursor position into the buffer (that is, directly into the text and prints it out on the screen). To exit insert mode and return to normal mode, type the exit key (ESC key, that is, Escape key).

In normal mode, if vim can correctly identify your terminal type (which would normally be possible), you can directly use the arrow keys to move the cursor in the text area.

Vim also has unique commands for moving the cursor.

H: move one character to the left

J: move down one character

K: move up one character

L: move one character to the right

Ctrl+F (PageDown): flip down one screen

Ctrl+B (PageUp): flip up the screen

G: move to the last line of the buffer

Num G: move to buffer line num

Gg: move to the first line of the buffer

The vim editor can press the colon key in normal mode: enter the command line mode and enter additional commands to control the behavior of the vim.

Q: if the buffer data is not modified, exit

Q! Cancel all modifications to buffer data and exit

W filename: save the file to another file

Wq: save buffer data to a file and exit

Hold down shift and press ZZ to save and exit

Hold down Shift and press ZQ to exit without saving

2. Edit data in normal mode

X: delete the character where the current cursor is located

Dd: deletes the line of the current cursor

Dw: deletes the word where the current cursor is located

Delete: deletes the current cursor position to the end of the line

J: delete the newline character at the end of the line where the current cursor is located (spliced line)

U: undo the previous editing command

A: appends data after the current cursor

A: append data to the end of the row where the current cursor is located

R char: replaces a single character in the current cursor position with char

R text: overwrites the data of the current cursor location with text until the ESC key is pressed

Some editing commands allow you to use numeric modifiers to specify how many times to repeat the command, for example, command 2x deletes two characters from the current position of the cursor, and the command 5dd deletes five lines from the current line of the cursor.

In addition, the vim editor usually recognizes the delete key (delete key) as the function of the x command in normal mode, but does not recognize the backspace key (backspace key).

3. Vim sets multiline indentation 1) multiline indentation method 1

First of all, press Esc to exit insert mode, then press Ctrl+v to select the lines to be indented, the up and down keys to select multiple lines, enter "I" (uppercase) and then press the Tab key once, you will find that only one line is indented, and then pressing ESC twice will indent all the selected lines.

The results are as follows:

2) Multi-line indentation method 2

You can use ctrl+v to enter visual mode, and then use the cursor movement or arrow keys to select multiple lines of code to indent, shift+' > 'indent to the left,'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report