Tools under linux---vim

1. Understand vim

1. vim is a development tool for linux

2. To put it simply, the difference between vi/vim is that they are both multi-mode editors. The difference is that vim is an upgraded version of vi. It is not only compatible with all instructions of vi, but also has some new features. inside. For example, syntax highlighting and visual operations can not only be run in the terminal, but also in x window, mac os, windows
3. Programming under Linux requires the use of independent development tools, vim is Nice tool

2. Basic concepts of vim

What we need to master are the three modes of vim: command mode, insert mode and last line mode.

1. Normal/Normal/Command mode (Normal mode)

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

2. Insert mode

Text input can only be done in Insert mode. Press the "ESC" key to return to the command line mode. This mode is the most frequently used editing mode we will use later.

3. Last line mode

Save or exit the file, you can also perform operations such as file replacement, string search, and line number listing. In command mode, press shift+: to enter this mode. To view all your modes: Open vim and type directly in the bottom line mode
 

 

3. Common operations of vim

Note: Most of the instructions introduced below are executed in the command mode. Some instructions are executed in the bottom line mode, and there will be special instructions, such as Chapter 1 One command set nu sets the line number

1. Enter vim, enter vim and the file name at the system prompt, and enter the vim full-screen editing screen:

Special note: After entering vim, you are in [normal mode]. You must switch to [insert mode] to enter text.
 

2. Switch from normal mode to insert mode

        in    

3. Switch [Insert Mode] to [Normal Mode]

Currently in [Insert Mode], you can only keep inputting text. If you find that you have entered a wrong word and want to use the cursor keys to move back and delete the word, you can first press the "ESC" key to go to [Normal Mode] and then delete it. Word. Of course, you can also delete it directly.

4. Switch from [Normal Mode] to [Last Line Mode]

"shift + ;" is actually typing ":"

5. Exit vim and save the file. In [normal mode], click the ":" colon key to enter "Last line mode", for example
: w (save the current file )
: wq (Enter "wq", save and exit vim)
: q! (Enter q!, force exit vim without saving)

4. vim normal mode command set

Row operation:

1. Delete
Delete the content of the line where the current cursor is: dd
Starting from the current cursor line, delete n lines: ndd

2. Undo
Undo the previous operation: u
Undo: ctrl+r

3. Replacement writing
shift r to enter the replacement mode, that is, the original code can be directly overwritten without deletion

Cursor positioning:

Position the cursor to the beginning of the file: gg
Position the cursor to the end of the file: shift + gg
Position the cursor to the file Any line of: n, shift+g

Position the cursor to the very end of the current line (anchor point): shift+$
Position the cursor to the very beginning of the current line (anchor point): shift+^

Move forward according to words: b
Move forward according to n words: nb

Move back according to words: w
Move back according to n words: nw

Delete the text content of the line where the cursor is located, one single character at a time from left to right: x
Delete the text content of the line where the cursor is, delete each time from right to left 1 character: shift + x

Convert letters to uppercase and lowercase: shift + ~
Convert letters to uppercase and lowercase: n, shift + ~

Cursor movement up, down, left and right: arrow keys or h (left), l (right), k (up), j (down)

Delete text:

"x": Each time you click, delete one character at the cursor position
"#x": For example, "6x" means to delete the character "after" the cursor position (including itself) Within)" 6 characters
"X": uppercase X, each time you press it, delete the character "before" the cursor position
"# ": For example, "20X" means to delete the "first" 20 characters at the cursor position
"dd": delete the line where the cursor is located
"#dd": Delete # lines starting from the line where the cursor is located

Additional system

"yw": Copy the characters from the cursor to the end of the word into the buffer.
"#yw": Copy # words to the buffer
"yy": Copy the line where the cursor is to the buffer.
"#yy": For example, "6yy" means to copy 6 lines of text "counting down" from the line where the cursor is located.
"p": Paste the characters in the buffer to the cursor position. Note: All copy commands related to "y" must be combined with "p" to complete the copy and paste functions.

Replace:
"r": Replace the character where the cursor is.

"R": Replace the character where the cursor is until the "ESC" key is pressed.

Batch comments:

To batch annotate:

       

5. Vim end line mode command set

Text search: /+Search for text, press n to select next
Text search: ?+Search for text, press n to select previous

Create line number: set + nu
Cancel line number: set + nonu

Save writing file: w
Force writing file: w!
Exit file: q
Force Exit: q!

Cross-file operation: vs + file name
Switch file window: ctrl + w + h/l

 

Guess you like

Origin blog.csdn.net/m0_69323023/article/details/134648732