vim and use of contrast source insight

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:

  1. 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.
  2. Multi-purpose ctrl+pintelligent 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.
  3. 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.
  4. 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 0line, with the inline search fbutton.
  5. 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 then Vselect 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, ppasted directly covering, cdelete and insert mode is switched to, and the like.
  6. Multi-file operations. Under the current file, perform :e filenameopen a new buffer to open a file, you can use e +enc=gbkthe specified encoding, :lsyou can see how many files are open, :b xxyou 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 autowriteyou can automatically save changes. Turn off buffer command bd, represents the buffer delete. According to Lenovo abbreviation complete words, help memory. There are many labels tabe xx, use gtto switch. Personally I prefer to use multi-buffer some of the current screen when writing code is the current file.
  7. That the current center line. zzThe current center line to the screen;
  8. Auto Indent When selected ==, the file on the many types of support;

Some write C / C ++ code tips:

  1. 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 may ctrl+ojump back, ctrl+ia jump forward. This is the basic use of the command ctags -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 xxjump to the symbol xx, or open after :tj xxthe jump.
  2. 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: vsvertically divided into two screens, spsideways 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.
  3. Directory traversal. Directly :e .open the current directory, :e %:hsee the open files in the current directory, you can easily compare the analysis of other files in the same directory, e: %r.hsee 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, gfrepresents a jump to go file file.
  4. Good use grep and copen. Sometimes the code to find, grep search is very convenient. In vim first :grep xxx -r dir, then :copenthere will be quickfix list, and ctrl+wtwice to jump to the split-screen quickfix list, and then press Enter to jump to the corresponding file with ctrl+iand ctrl+othe jump back and forth easily. Such as: search contents .c and .h in grep -Ir --include "*.[ch]" "xx"you can specify the directory search in the specified file type. Copy command mode word under the cursor is ctrl+r ctrl+wa combination of very easy to use, remember to press ctrl with left hand part. Exit the current window directly :qto exit the other split-screen only keep current with the :onlycommand;
  5. Paste. Settings :set paste, and then paste the clipboard contents external format so there is not as automatic indentation caused confusion, close by set nopaste.
  6. Close line number. Sometimes need to copy the contents to the outside, it does not require line numbers, set nonuquickly turn off line numbering, set nuthen the display back.
  7. Close highlighted. Often *key to highlight the search word under the cursor, set nohturn off highlighting, next time will highlight the search again.
  8. Folding function. Selected vi{when selected within the braces, and then zfthe folded portion is selected, zoopen 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.

Published 140 original articles · won praise 160 · views 320 000 +

Guess you like