Build and use the Linux development environment -- vim and linuxvim in common Linux editors
Overview
Vi editor is the most commonly used text editor in Linux systems. In the Linux field, vi has the reputation of "Editor". Almost all Linux releases contain vi programs.
Vi works in character mode and does not require a graphical interface. It is very suitable for remote and embedded work and is a highly efficient text editor. Although there are many Graphical Editor available in Linux, however, vi functions are incomparable to those of graphic editors.
So what is vim?
Vim is an upgraded version of vi. It is not only compatible with all instructions of vi, but also has some new features, for example, vim can undo unlimited times, support automatic keyword completion, and highlight your code in different colors. Vim is generally regarded as one of the best in the class vi editor.
Official Website: http://www.vim.org/download.php
When vim is usedCtags. Ctags is a tool that facilitates code reading in vim. It is a powerful vim plug-in that can jump between functions and variables when you browse code.
Official Website: http://ctags.sourceforge.net/
Preparations
Install vim and ctags:
Sudo apt-get install vim
Sudo apt-get install ctags
Configure vim:
Here is an article about vim configuration. You can click here.
Here is a step file that has been configured (download and click it). You can complete the configuration by running the step.
Vim is the simplest and most commonly used operation.
The following operations are equivalent to the vi or vim command.
First, we will introduce you to the simplest and most common operations (open a file, edit a file, and save a file). If you do not want to explore these operations in depth, you can simply learn these operations.
Use vi to open a file
Vi filename: open or create a file and place the cursor at the beginning of the first line
If the file does not exist, a new file is created as follows:
If the file exists, that is, open the file. After opening the file, press "I" to enter the insert mode before editing:
As a result of vim configuration, you can click "F9" to switch between hidden display columns.
By default, files cannot be edited directly when they are opened:
Press "I" to enter the insert mode and you can edit it:
Vi + n filename: open the file and place the cursor at the beginning of line n
Save an object (one of the following methods ):
Be sure to exit the insert mode first, and then shift + zz (Press "shift" + double-click "z") To save and exit the current file.
Detailed use of vim
The vim editor has three operation modes (the mode name is not important, and I don't know the total score, so I can know what to do in each mode ):
1. vi insertion Mode
When creating a non-existing file, vi enters the insert mode by default.
Vi places the entered characters as the body content in the file being edited
2. vi editing mode
When opening an existing file, vi enters the editing mode by default.
In this mode, you can enter the insert mode, control the movement of the screen cursor, select, copy, paste, cut, delete, and search the text.
3. The last line of vi (command mode)
In edit mode, pressShift"+":"Enter
Similar to the editing mode, the task of saving, saving, and searching a disk is completed.
Mode switch:
Switch from edit mode to insert mode
I insert from the current position of the cursor
A is inserted starting from the next character at the current position of the cursor.
O insert an empty row in the downlink of the cursor and then insert it.
I insert the body from the beginning of the row where the cursor is located
A. Insert the body from the end of the row where the cursor is located.
O insert an empty row in the previous line at the cursor position before inserting
Switch from edit mode to last line mode (command mode)
"Shift" + ":"
Switch from insert mode to edit mode
Esc (command mode to edit mode twice Esc)
The insert mode and command mode cannot be directly converted.
Delete and modify text in edit mode
1. u undo the previous modification multiple times.
2. [n] x Delete n characters after the cursor.
3. [n] X Delete the first n characters of the cursor.
4. [n] dd Delete the n rows starting from the current row (specifically, cut is used, and cut is deleted if it is not pasted ).
5. [n] yy: Copy n rows starting from the current row.
6. p inserts the content on the clipboard into the current row.
7,.Perform the last operation
8. shift + zz (hold down shift and press the z key twice) to save and exit the current file
Copy in edit mode
Copy a word from yw
Dw clipboard a word
Cw modifies a word
Block Selection command
V: select by character
D: paste the selected content to the clipboard.
Y: copy the selected content to the clipboard.
C: paste the selected content to the clipboard and enter the insert mode.
(N) shift +> move a tab to the right of the selected content
(N) shift + <move the selected content to the left
Move the cursor in edit mode
[N] G: move the cursor to the beginning of line n.
G: move the cursor to the end of the file.
Gg: move the cursor to the beginning of the file.
Search in edit mode
/String: searches the end Of the file from the cursor.
N: Repeat the previous search command in the same direction.
N: Repeat the previous search command in the opposite direction.
Common last line mode commands
File Storage
: W: Save the current file
: W file saves the current file as another file
: Q: Exit vi
: Wq: Save the current file and exit.
: X same as above
: Q! Do not save the file and exit
Multiline cut and copy in Normal Mode
: N1, n2 d cut the content between n1 and n2 to the clipboard
: N1, n2 m n3 cut content from line n1 to line n2 to line n3
: N1, n2 co n3 copy content from line n1 to line n2 to line n3
Search and replace in the last line
: S/p1/p2/g replace all p1 in the current row with p2
: G/p1/s // p2/g replace all p1 files with p2
: N1, n2s/p1/p2/g replace all p1 from n1 to n2 with p2.