After using emacs for nearly two years, I did not expect that I would not have the opportunity to feel it when I entered the company .. All of them are in the bare environment, and once or twice it is okay ..
Switch to the vi camp is not just an environmental reason. I feel that the vi operation is faster and it will greatly improve the efficiency if I stick to some commands for a long time.
3.27. The ctags are still being explored in several new areas ·
Zero-browsing code
When getting open source code or similar legacy code, reading is essential. I usually like to browse the code, length, format, and whether it meets my personal aesthetic point of view first, then start learning. Therefore, the first commonly used command is to open the text Browser: {} is still a habit in windows for many years. It is still very nice to check the code in coloring and freely available, in one breath, open the code files in the folder. From the main point of view, you can guess the name, and open all the files if you cannot guess the name. IDE functions.
1. open the file:
Different from step 1, here we will introduce some of the commands required to use vi to view Code recently. It takes a lot of time for bing. Remember this and save searching for it.
Vi filename
Will open the file and stay in the Last edited location
Improve efficiency:
When you modify the code, you often remember the number of lines you want to modify and the features of the field. After all, the code is problematic or you have considered finding it. Therefore, locating the file opening location can greatly improve the efficiency.
Vi + n filename specifies the number of lines to jump to the Open File
Vi +/xx filename open the file and jump to the line containing content
2. Browsing
Next Previous Page
Ctrl + f Ctrl + B 0 $ [[]
The most commonly used commands are the following. These commands have been used for the past few days. I tried to press ESC and then press and hold l...
You can directly enter numbers and then enter these commands. For example, you can switch back to line 200 at 200 k.
The next line, the last line, the last one, the last one, and the next word
J k h l e B
Use
Ctrl + g report current row and column information
Ngg or: n jump to the specified row n
Jump to the first line and you can directly use gg
H move to the top of the screen
M moves to the center of the screen
L move to the bottom of the screen
Edit 3
Editing, no nonsense, very fond of vi input, all the functions you Want to do are available
I insert at the cursor
Insert at the beginning of period I
Insert after a cursor
Insert at the end of A sentence
O Insert a new row
J. Merge the next row into the current row
Improve efficiency:
: Set ai to enable automatic alignment. It is better to write code ~
R replacement of characters at the specified position does not enter the insert mode. It is the perfect solution to replace a few letters. We strongly recommend that you use
R replacement Mode
S is inserted after the current character is deleted. It is also often used as a replacement of the character s + esc before entering the edit mode after the character needs to be replaced .. Until we find the strongly pushed r
Cc deletes and edits the entire row.
Add vim Configuration:
Create or edit the. vimrc file in the user directory
Add set autoindent
Set softtabstop = 4
Automatic Alignment and soft tab.
Delete
Delete the current character using x or dl
X or dh Delete the previous character
Dd deletes the current row
D] Delete to the end of the document
Copying and pasting is also a common task for programmers. Similar statements are used to copy and paste the three or four lines, and then use regular expressions to change the regular expression to the desired word.
Copy a word from yw
Yy copy a row
Nyy copy n rows
Copy yG to the end of the article
Copy y1G to the beginning of the article
"Xnyy copies n rows to the variable x (any letter). The output function can be copied to p, so that nothing else needs to be copied, and the output will be copied back :)
: You can use the command to view the information if reg copies a variable that you do not remember ~
P paste corresponds to the yy command
Copy selected multiple rows
V enters visual mode and moves the cursor to select the text. V is the unit of action.
Y Copy d Delete
: S/old/new/g easily replaces all old-new in a row. If only the first one in the row is replaced, removing the last/g is a common regular expression.
If you want to replace the number of rows in the specified range, simply add the preceding
: S/create/delete/g where. indicates the current row and # indicates the last row.
You can use
: % S/old/new/g
Search
One of the most common functions is to see the code before dozens of lines to modify, but when the number of lines is not estimated, you can directly look at the features and then find ~
/Xx
? Xx search for the previous xx
N Continue search
N reverse search
Undo
U cancels the last operation
Ctrl + R restore u
Iv. Functional commands
: W save
: Q exit
Saving and exiting a quick command can save the programmer a lot of time. After I input n + 1 wq sadly, I found that they are collectively called x
ZZ saved and exited and found a new one, which is better!
5. Tips
Historical name
: Ctrl + p. This is obviously a traditional usage.
: Ctrl + f Recent History commands, which are newly discovered and easy to use!
Place the output result of command to the current line
: R! Command can be used to insert some local information such as: r! Ifconfig eth0 grep "inet" puts the IP address information of the local machine directly in the vi document.
Display man content of words under the cursor
K
Display the hexadecimal value of Unicode characters under the cursor
G8
Bookmarks
When you need to mark the Code:
MX: X is any letter
Jump to bookmarks:
'X
Save and exit: ZZ is very convenient
Code Movement
: Set sw? View the number of code moves at a time
: Set sw = 4 set 4 bits (it is important to write code or 4 bits :)
: Le |: ce |: ri positioning left-right
Vi. Multi-document editing
Previously, I thought it was inconvenient to edit multiple vi Documents. Now I have some contact with MiniBufExplorer and found that it is not very comfortable. It is better to use ls.
: Ls displays all open documents
: Switch xn to the x document below
N ctrl + 6: switch to the nth buffer
Ctrl + 6 or: e # return to the previous editing File
Split screen
: New xxx
Ctrl + w s split-screen display of the current document content
Ctrl + w q close the split screen
Ctrl + w o only displays the current split screen content
Ctrl + w j k select up/down split screen
I personally think the most useful command is ctrl + w to quickly switch between the two screens on the split screen.
I haven't written the following ~ After reading this article, I think these are pretty good.
: N1, n2 co n3: copy the content from line n1 to line n2 to line n3.
: N1, n2 m n3: Move the content from line n1 to line n2 to line n3
: N1, n2 d: Delete content from line n1 to line n2
: N1, n2 w! Command: The content from line n1 to line n2 in the file is used as the command input and executed,
If n1, n2 is not specified, the entire file is used as the command input.