Overview
VI Editor is the most commonly used in Linux system Text editor, vi in the Linux world has the editor of God's reputation in almost all Linux distributions are included in the VI program.
vi work in character mode, do not need a graphical interface, very suitable for remote and embedded work, is a very efficient text editor, although there are many graphical interface on Linux editor is available, but the function of the vi is those graphics editor can not match.
What about VIM?
Vim is an upgraded version of VI, it is not only compatible with all VI directives, but also some new features, such as Vim can be undone unlimited, support keywords auto-complete, you can use different colors to highlight your code. Vim is generally respected as the best of the Class VI editor.
Official website: http://www.vim.org/download.php
When using VIM, universal needs ctags tool assist . Ctags is a handy code reading tool under Vim and is a powerful vim plugin that allows you to jump in and out of functions, variables, and so on while browsing through the code.
Official website: http://ctags.sourceforge.net/
preparatory work
Install Vim,ctags:
sudo apt-get install vim
sudo apt-get install Ctags
Configure VIM:
Here is a "VIM configuration note", you can click to see.
Here is an already configured footstep file (download direct click), run the steps to complete the corresponding configuration.
Vim's simplest and most common operation
The following operations, using the VI or VIM commands are equivalent.
let's introduce one of the simplest and most commonly used operations (Open the file, edit the file, save the file), if you do not delve into, learn these several operations can.
Open file with VI
VI filename: Opens or creates a new file and places 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 you open the file, press "I" to enter the Insert mode before you can edit:
Due to the VIM configuration reasons, such as the column, press "F9" to realize the hidden display of the column switch.
By default, the file is opened and cannot be edited directly:
Press "I" to enter insert mode to edit:
vi +n filename: Opens the file and places the cursor at the beginning of the nth line
Save the file (one way):
Be sure to exit the Insert mode first , thenSHIFT + ZZ ( Press and hold "shift" + Press the "Z" key ) to save the current file.
Vim's detailed use
Vim Editor has 3 modes of operation ( the name of the mode is not important, I am not clear, I know what to do in each mode ):
1. VI Insert mode
VI when creating a nonexistent file, enter insert mode by default
VI Place the entered character as body content in the file being edited
2, vi editing mode
VI opens a file that already exists and enters edit mode by default
In this mode, you can enter the insertion mode, control the movement of the screen cursor, make text selection, copy, paste, cut, delete, find and so on.
3, vi last line mode (Command mode)
In edit mode, press "shift" + " : " to enter
Similar to edit mode, complete tasks such as saving, save, and find
Mode switch:
Switch from edit mode to insert mode
i insert from the current position of the cursor
a inserts from the next character in the current position of the cursor
o insert a blank line in the downstream of the cursor position, then insert
I Insert Body from the beginning of the line where the cursor is located
A Insert Body from the end of the line where the cursor is located
O Insert a blank line at the previous line of the cursor position, and then insert
Switch from edit mode to last line mode (Command mode)
"Shift" + ":"
Switch from insert mode, command mode to edit mode
ESC(Command mode to edit mode two times ESC)
Insert mode and command mode cannot be converted directly
Delete and modify text in edit mode
1, u undo the previous changes several times.
2.[n]x deletes the n characters after the cursor.
3.[N]x deletes the first n characters of the cursor.
4.[N]dd deletes the n rows starting from the current line (to be exact, cut, cut without pasting or deleting).
5,[n]yy copies n rows starting from the current line.
6, p inserts the contents of the pasteboard into the current line.
7, . perform the last action
8,shift +zz (hold down SHIFT and press the Z key) to save the current file
Copy in edit mode
yw copy a word
DW Clip a word
CW modifies a word
Block Selection command
v: Select by character
d: Clip the selected content to the Clipboard.
y: Copies the selected content to the Clipboard.
C: Clip selected contents to Clipboard and enter insert mode
(n) Shift + > Selection Move one tab to the right
(n) Shift + < selection moves left one tab
Move the cursor in edit mode
[n]g: Positions the cursor at the beginning of the nth row
G: Position the cursor at the end of the file
GG: Position the cursor at the beginning of the file
Find in edit mode
/String : Finds a string at the end of the file from the beginning of the cursor.
N: Repeat the last lookup command in the same direction
N: Repeat the last lookup command in the opposite direction
Common last line Mode command
File Storage class
: w Save current file
: W file Save the current file as files
: Q Exit VI
: Wq Save current file, exit
: x Ibid.
: q! Do not save the file and exit
Multi-line cut, copy in normal mode
: n1,n2 D cuts the contents of the N1 to N2 rows to the Pasteboard
: n1,n2 m n3 cut the contents of N1 rows to N2 rows to N3 rows
: N1,N2 Co n3 Copy the contents of the N1 line to the N2 row below the N3 line
Find and Replace in last line mode
: s/p1/p2/g replaces all P1 in the current row with P2
: g/p1/s//p2/g replaces all P1 in the file with P2
: n1,n2s/p1/p2/g N1 to N2 row all P1 are replaced with P2
Vim for building and using the Linux development environment--linux Common editor