From the beginning of 2019, more and more use of vim, has been a source insight before with more. Why the sudden vim use more of it? Because some external factors, the company began to gradually not to use source insight, coupled with the code base is compiled on a Linux machine, directly SSH to a Linux server modify the compiler more convenient.
First talk about the source insight experience. For C / C ++ project, source insight look at the code it is pretty easy. Find the file, looking for symbols, fuzzy search, add bookmarks, see the function call graph (this particular praise) are very easy to write code intellisense although not as accurate as VS IDE such as but adequate. Drawback is more general text editing experience, and only supports Windows platforms, the degree of freedom is relatively low. Overall, source insight look at the code for Windows, the learning cost is very low, different scenarios using the right tools themselves can use the efficient completion of the work, which is good, no need to paranoia.
The next focus here vim experience. vim with skilled, and write code there will be a smooth writing feeling, my thinking changes can react quickly to modify the corresponding code to quickly find the point you want to modify, combined operation to quickly modify the content they want to change, you can He said write code in a way to improve the experience, so write code becomes more cool.
vim has some learning costs, but this is definitely worth the investment, after skillfully edited various text and other code and configuration of the speed will be much improved, most Linux distributions are built in vim, and mode of operation are a lot of command vim is integrated, and there are a variety of IDE plug-vIM. The best way is to learn vim to use them again, and then combine their usage scenario, see the help, information search, constantly optimize their methods of operation, summed up his experience. Before he still wrote two small sum to get started:
vim is a multi-mode design, various combinations can do a lot of complex operations in different modes, familiar with the operation of this combination, the editing efficiency will improve a lot. Introductory level, the first five chapters vim help of a good look, a good English can help explain the meaning of the corresponding shortcut keys, easy to remember, such as is the cw change word. Here to talk about some of their usual experience:
Some general editing tips:
- Multi-use shortcut keys native. Do not change too much of their own special keys, free of for the machine will not operate. Many people will map the ESC key, I also started thinking about doing, but after a period of practice, found to his left ring finger, press ESC no problems, ctrl key using the left hand to press, hand type do not become too soon You will be able to adapt.
- Multi-purpose
ctrl+p
intelligent association, has entered words, symbols of ctags database can think of it. This function is very powerful, operate in multi-purpose terminal must learn this can greatly improve efficiency. - Multi-purpose
.
operation, the foregoing operation is repeated. To pass in front of a complex operation, move the cursor to a specific position, directly by.
repeated very convenient. - Shortcuts do not need to remember very much under common scenario most common and easy to remember on the line. For example, to jump to the first line by
0
line, with the inline searchf
button. - and a variety of visual mode to jump together, it will be more convenient to select and then delete modification and other operations. Such as resolving conflict git, go jump rope
^<<
then, and thenV
select the line, jump to the search^===
, to select a part of the conflict;/x然后跟方向键
you can think of all the history of the beginning of x entered search. When selected,p
pasted directly covering,c
delete and insert mode is switched to, and the like. - Multi-file operations. Under the current file, perform
:e filename
open a new buffer to open a file, you can usee +enc=gbk
the specified encoding,:ls
you can see how many files are open,:b xx
you can jump in the past, you can use tab Lenovo Jump designated xx. You need to save the file before jumping to modify the current buffer,set autowrite
you can automatically save changes. Turn off buffer commandbd
, represents the buffer delete. According to Lenovo abbreviation complete words, help memory. There are many labelstabe xx
, usegt
to switch. Personally I prefer to use multi-buffer some of the current screen when writing code is the current file. - That the current center line.
zz
The current center line to the screen; - Auto Indent When selected
==
, the file on the many types of support;
Some write C / C ++ code tips:
- Install what ctags and cscope, two plug-ins are very common and well installation. See definitions ctags
ctrl+]
, cscope see reference to the definition of the reference or mayctrl+o
jump back,ctrl+i
a jump forward. This is the basic use of the commandctags -R --extra=f;cscope -Rb
, executed in the root directory of the project. Do not look at the code into a specific directory in the root directory starts vim,vi -t xx
jump to the symbol xx, or open after:tj xx
the jump. - General IDE to write code are smart tips for VIM, there is a corresponding YouCompleteMe plug-in, but the plug-in installation configuration is too much trouble. Well, if this is not YCM plug-in, then make good use of split screen:
vs
vertically divided into two screens,sp
sideways split screen, write code in a split-screen, split-screen look at the other related code or definition of the structure, function declarations and so on, write Code mind also appropriate to remember a number, do not rely too much on intelligence suggests. - Directory traversal. Directly
:e .
open the current directory,:e %:h
see the open files in the current directory, you can easily compare the analysis of other files in the same directory,e: %r.h
see the local head of the same name to the current file. Skip header file system location, the cursor on the file name at the head,gf
represents a jump to go file file. - Good use grep and copen. Sometimes the code to find, grep search is very convenient. In vim first
:grep xxx -r dir
, then:copen
there will be quickfix list, andctrl+w
twice to jump to the split-screenquickfix list
, and then press Enter to jump to the corresponding file withctrl+i
andctrl+o
the jump back and forth easily. Such as: search contents .c and .h ingrep -Ir --include "*.[ch]" "xx"
you can specify the directory search in the specified file type. Copy command mode word under the cursor isctrl+r ctrl+w
a combination of very easy to use, remember to press ctrl with left hand part. Exit the current window directly:q
to exit the other split-screen only keep current with the:only
command; - Paste. Settings
:set paste
, and then paste the clipboard contents external format so there is not as automatic indentation caused confusion, close byset nopaste
. - Close line number. Sometimes need to copy the contents to the outside, it does not require line numbers,
set nonu
quickly turn off line numbering,set nu
then the display back. - Close highlighted. Often
*
key to highlight the search word under the cursor,set noh
turn off highlighting, next time will highlight the search again. - Folding function. Selected
vi{
when selected within the braces, and thenzf
the folded portion is selected,zo
open the selected portion.
The VIM efficient to use them, do not need more complex configuration and does not require a lot of complicated plug-ins. To do just SSH to a Linux server, under slightly modified vimrc can conduct their work efficiently. Configure and optimize the operation can be encountered with the use of their own scene and gradually improved.