Recently I am reading the book "TCP/IP protocol strated volume2: The Implementation". Naturally, I need to download the source code of 4.4bsd-lite and study it together with books. When I used to learn vim, I knew that Vim could use the plug-in function to configure a powerful custom ide. Why didn't I take advantage of this opportunity? As a result, a simple and complete IDE environment is configured step by step as needed during the process of reading the source code. Through the past few days, I feel that Vim is easy to use and the speed is fast. I used to hear how Vim works. This time it really made me feel and fell in love with vim. It is strongly recommended that you try it yourself if you have not tried it. Let's take a look at how I configure Vim as a fully functional ide step by step.
I. Preparations
- Install git (because the plug-in manager we selected below needs to be used)
- Before installing other plug-ins, You must select a Vim plug-in manager. Here, vundle is selected, during vundle's work, you need to use git to automatically synchronize the plug-in installation package from remote database creation to the local repository (the default local repository location of vundle is ~ /. Vim/bundle /)
- Download the vundle installation package through git: $ git clone https://github.com/gmarik/Vundle.vim.git ~ /. Vim/bundle/vundle. Vim
- In ~ /. Add vundle configuration in vimrc:
1 set nocompatible " be iMproved, required 2 filetype on " required 3 4 " set the runtime path to include Vundle and initialize 5 set rtp+=~/.vim/bundle/Vundle.vim 6 call vundle#begin() 7 " alternatively, pass a path where Vundle should install plugins 8 "call vundle#begin(‘~/some/path/here‘) 9 10 " let Vundle manage Vundle, required11 Plugin ‘gmarik/Vundle.vim‘12 13 " plugin from http://vim-scripts.org/vim/scripts.html14 Plugin ‘L9‘15 " Git plugin not hosted on GitHub16 " Plugin ‘git://git.wincent.com/command-t.git‘17 " git repos on your local machine (i.e. when working on your own plugin)18 " Plugin ‘file:///home/gmarik/path/to/plugin‘19 " The sparkup vim script is in a subdirectory of this repo called vim.20 " Pass the path to set the runtimepath properly.21 " Plugin ‘rstacruz/sparkup‘, {‘rtp‘: ‘vim/‘}22 " Avoid a name conflict with L923 " Plugin ‘user/L9‘, {‘name‘: ‘newL9‘}24 25 " All of your Plugins must be added before the following line26 call vundle#end() " required27 filetype plugin indent on " required28 " To ignore plugin indent changes, instead use:29 "filetype plugin on30 "31 " Brief help32 " :PluginList - list configured plugins33 " :PluginInstall(!) - install (update) plugins34 " :PluginSearch(!) foo - search (or refresh cache first) for foo35 " :PluginClean(!) - confirm (or auto-approve) removal of unused plugins36 "37 " see :h vundle for more details or wiki for FAQ38 " Put your non-Plugin stuff after this line
View code
- There are two ways to install the new plug-in: $ VIM + plugininstall + qall or run: $ Vim directly, and then press: plugininstall to enter the command mode, until done appears in the lower-left status bar! The prompt indicates that the plug-in is successfully installed. You can use the plug-in after exiting the plug-in ~ /. The plugin configured in vimrc
- Install the ctags software: $ Yum install ctags
Ii. Generate a tags File
To use the tag function provided by VIM to locate the macro definition and method definition in the Program (jump between source files), run the following command in your project root directory: $ ctags-r -- language-force = C ++ *. The language here must be specified as C ++. If it is specified as C, it will not be generated. the tag of the H file. After the operation is successful, a tags file can be found in the current directory ~ /. Add a configuration line in vimrc, for example, set tags =/opt/dev/4.4bsd-lite/tags, to tell the location of the vim tag index file. Run Vim again and press Ctrl +] to quickly jump to the function or macro definition at the bottom of the cursor. It is very convenient to view the code. You can use] + D to display the macro content defined in the current file in the vim Status Bar (Skip is not required)
3. Add plug-ins as needed
(1) nerdtree)
- In ~ /. Add a line of installation configuration in the plugin section of vimrc: plugin 'scrooloose/nerdtree'
- In ~ /. Modify the open command ing of the plug-in vimrc: Map <F4>: nerdtree <CR>
- Save the modified configuration file and run Vim again, for example: $ Vim/opt/dev
- Press the F4 function key to call this plug-in to display the directory tree of the current working directory. Press? Or help information, press Q to exit the plug-in (when multiple tabs are opened, you can quickly switch between tabs through GT or window index + GT, press t to open the new tab in a quiet mode. That is, the new tab is opened and then left in the current tab)
(2) file search plug-in (ctrlp)
- In ~ /. Add a line of installation configuration in the plugin section of vimrc: plugin 'kien/ctrlp. Vim'
- In ~ /. Modify the open command button ing and configuration of the plug-in vimrc:
let g:ctrlp_map = ‘<c-p>‘ "hotkey Ctrl+p open ctrlp pluginlet g:ctrlp_cmd = ‘CtrlP‘let g:ctrlp_working_path_mode = ‘0‘ "disable work path mode
- Save the modified configuration file and run Vim again, for example: $ Vim/opt/dev
- Press Ctrl + P to call the plug-in. (wait a moment to open the plug-in for the first time. The plug-in scans the working directory to create a cache. If the directory structure changes, press F5 to refresh the cache, I found the function of saving the scan cache.) Press ESC to exit the plug-in (CTRL + t open the selected file in the new tab );: ctrlpmru query results in the most recently used files;: ctrlpbuffer query results in the find buffer; Press .. go to the upper-level directory
(3) Function Name List (ctrlpfunky), which is an extension of the ctrlp plug-in. ctrlp must be installed first.
- In ~ /. Add a line of installation configuration in the plugin section of vimrc: plugin 'tacahiroy/ctrlp-Funky'
- In ~ /. Modify the command key ing and configuration of the plug-in vimrc:
map <F6> :CtrlPFunky<cr>let g:ctrlp_extensions = [‘funky‘]let g:ctrlp_funky_syntax_highlight = 1
- Save the modified configuration file, run Vim again to open a C source file, press F6 to view the function list of the current file, move the selection entry up/down key, and press enter to jump to the Function Definition
(4) list of functions, variables, struct, macros, and other elements in the source file (taglist)
- In ~ /. Add a line of installation configuration in the plugin section of vimrc: plugin 'vim-scripts/taglist. Vim'
- In ~ /. Modify the command key ing and configuration of the plug-in vimrc:
map <F5> :Tlist<cr>let Tlist_Show_One_File = 1let Tlist_Exit_OnlyWindow = 1 let Tlist_Use_Right_Window = 1let Tlist_GainFocus_On_ToggleOpen = 1
- Save the modified configuration file and run Vim again to open a C source file. Press F5 to view the list of elements in the current file in the right subwindow, press enter to jump to the function definition. F1 can view the help information and press <space> on the selected object to view the definition of each element in the status bar; close a node by minus (-) and press * to open the closed node.
ThuPostscript
The above four plug-ins are the IDE configurations I have read the source code. For me, they are enough to meet my work needs; in this rush of time, there are still a lot of user-friendly configurations and plug-ins in VIM before I can find out. With my more in-depth understanding of vim and new problems encountered during use, there will be more outstanding functions and plug-ins, and we will share them later.
To save the working status of each operation and resume the previous running status when running Vim again, you need ~ /. Add the following two lines in vimrc (that is, the session management function of VIM ):
map <F2> :mksession! ~/vim_session <cr> " Quick write session with F2map <F3> :source ~/vim_session <cr> " And load session with F3