Build vim into a real IDE

Source: Internet
Author: User

 

Ten required Vim Plugin

Http://www.openfoundry.org/en/tech-article/2244

 

The configuration of vimrc is as follows (for the sake of simplicity, you can directly describe it using annotations ):

If (has ("win32") | has ("win95") | has ("win64") | has ("win16 ")) "determine the current operating system type let g: iswindows = 1 else let g: iswindows = 0 endifset nocompatible" do not use vim to imitate the vi Mode. We recommend that you set it, otherwise, there will be many incompatibility issues. syntax on "turn on the highlighted if has (" autocmd ") filetype plugin indent on" indent augroup vimrcEx au Based on the file! Autocmd FileType text setlocal textwidth = 78 autocmd BufReadPost * \ if line ("'\" ")> 1 & line ("' \ "") <= line ("$ ") | \ exe "normal! G' \ "" | \ endif augroup ENDelse ": Smart indentation. cindent is used. autoindent can be used to indent various files, however, the effect is worse than that of cindent that only supports C/C ++. However, I have not found that set autoindent "always set autoindenting on endif" has ("autocmd ") set tabstop = 4 "make a tab equal to four spaces set vb t_vb = set nowrap" do not automatically wrap set hlsearch "highlighted result set incsearch" when entering the text to be searched, vim will match set backspace = indent, eol, start whichwrap + = <,>, [,] in real time to allow the use of the backspace key if (g: iswindows = 1) "Allow the mouse to use" to prevent the linux terminal from copying if has ('Mouse ') set mouse = a endif au GUIEnter * simalt ~ Xendif "font settings set guifont = Bitstream_Vera_Sans_Mono: h9: cANSI" Remember to use underscores (_) to replace set gfw =: h10: cGB2312

OK, with the basic settings above, a good vim is configured, but if you want to make it perfectly support various source code files, you want to make it easy to comment, code prompts are easy to add user information, which is far behind.

We have configured a VIM that can be used normally. Before we really come to the programmer's VIM world, we hope you can add the following configurations in VIM.

Set go = "no menu, toolbar"

Right, let me really discard the mouse and enter the wonderful VIM journey!

First, let's talk about several functions that an IDE should have:

1) source code structure and function list

2) variable definition supports redirection.

3) Automatic Code Completion

Of course VIM also gave us a few small surprises:

4) Fast batch comment and reverse comment

5) directly generate a document by commenting

6) automatically add the file header author information

7) fast switching between. cpp and. H files

Next, let's take a long look at the list of plug-ins we will use.

First, let's introduce some essential knowledge. We need the following two things to help complete vim's great journey to IDE-ctags and csags. These two things are not vim plug-ins but executable programs, both linux and windows. Ctags provides Intelligent Analysis for languages such as c, c ++, java, and c #, and claims the tags file. All the following information includes the function list display and variable definition jump, automatic completion depends on him. With the tags file, you only need to press CTRL +] on the variable to automatically jump to the position defined by the variable. Csflood is said to have been born to replace ctags because it has more powerful functions than ctags. For example, ctags can only analyze where this function is defined, in addition to this, cssag can also analyze where this function is called. Of course, there are still many bugs in csflood, but it does not affect our use.

1) taglist. vim provides a powerful display of the source code structure and function list.

2) tags is automatically supported.

3) omnicppcomplete. vim automatically completes Writing C/C ++ Language

4) NERD_commenter.vim annotation plug-in

5) DoxygenToolkit. vim is generated by the annotation document and can quickly generate the function standard Annotation

6) I wrote this configuration and posted it later.

7) a. vim implements fast switching between. cpp and. h.

The following explains the configurations one by one:
Note: Check whether the following configuration exists. If not, add the following Configuration:

if(has("win32") || has("win95") || has("win64") || has("win16"))    let g:vimrc_iswindows=1else    let g:vimrc_iswindows=0endifautocmd BufEnter * lcd %:p:h

Check that the ctags and csags are installed, and that the directories of the two executable programs are included in the environment variables. (Required. Otherwise, no operation can be performed later)

The configuration in vimrc is as follows:

map <F12> :call Do_CsTag()<CR>nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>function Do_CsTag()    let dir = getcwd()    if filereadable("tags")        if(g:iswindows==1)            let tagsdeleted=delete(dir."\\"."tags")        else            let tagsdeleted=delete("./"."tags")        endif        if(tagsdeleted!=0)            echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None            return        endif    endif    if has("cscope")        silent! execute "cs kill -1"    endif    if filereadable("cscope.files")        if(g:iswindows==1)            let csfilesdeleted=delete(dir."\\"."cscope.files")        else            let csfilesdeleted=delete("./"."cscope.files")        endif        if(csfilesdeleted!=0)            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None            return        endif    endif    if filereadable("cscope.out")        if(g:iswindows==1)            let csoutdeleted=delete(dir."\\"."cscope.out")        else            let csoutdeleted=delete("./"."cscope.out")        endif        if(csoutdeleted!=0)            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None            return        endif    endif    if(executable('ctags'))        "silent! execute "!ctags -R --c-types=+p --fields=+S *"        silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."    endif    if(executable('cscope') && has("cscope") )        if(g:iswindows!=1)            silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"        else            silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"        endif        silent! execute "!cscope -b"        execute "normal :"        if filereadable("cscope.out")            execute "cs add cscope.out"        endif    endifendfunction

1) taglist. vim

Take a screenshot to see:

Put taglist. vim In the plugin directory and add the following configuration in vimrc:

"Perform Tlist Settings" TlistUpdate can update tagsmap <F3>: silent! Tlist <CR> "Press F3 to call out let Tlist_Ctags_Cmd = 'ctags '. Because we put it in the environment variable, we can directly execute let Tlist_Use_Right_Window = 1" to display the window on the right, 0 is displayed on the left. let Tlist_Show_One_File = 0 "enables the taglist to display the function list of multiple files at the same time. If you want to have only one function list, set it to 1let Tlist_File_Fold_Auto_Close = 1" non-current file, function list collapse hide let Tlist_Exit_OnlyWindow = 1 "When taglist is the last split window, vimlet Tlist_Process_File_Always = 0" whether to process tags.1: processing; 0: Not processing. Instead of updating tags in real time, it is not necessary to let Tlist_Inc_Winwidth = 0

2) I have already explained it above, so I will not repeat it here

OK. Now, we can successfully display the function list and view the function definition. There is no problem reading the code. The rest is the plug-in to be used during code writing.

Previously, it was convenient and easy to read code in VIM. Now we can make it easier to write code in Vim ~ Then you can discard tools like sourceinsight ~

3) omnicppcomplete. vim automatically downloads the plug-in when writing C/C ++

4) NERD_commenter.vim comment plug-in download plug-in

It is also a very practical plug-in for programmers, supporting the completion of various languages, as long as you can think of, rest assured that he is absolutely annotated, and also supports single line annotations, batch annotations, and other command ing. Here, I configured the most common key ing in vimrc.

"Let NERDShutUp = 1 for the setting of NERD_commenter

In this case, in the row where the cursor is located, press ctrl + h for the comment, and then press ctrl + h to cancel the comment.

While its built-in commands, cm is a multi-line annotation, similar to C ++'s/**/, and cu is to cancel the annotation.

5) DoxygenToolkit. vim is generated by the annotation document and can quickly generate the function standard Annotation

This plug-in allows vim to generate standard function comments.

map fg : Dox<cr>let g:DoxygenToolkit_authorName="dantezhu"let g:DoxygenToolkit_licenseTag="My own license\<enter>"let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"let g:DoxygenToolkit_briefTag_pre = "@brief\t"let g:DoxygenToolkit_paramTag_pre = "@param\t"let g:DoxygenToolkit_returnTag = "@return\t"let g:DoxygenToolkit_briefTag_funcName = "no"let g:DoxygenToolkit_maxFunctionProtoLines = 30

You can set DoxygenToolkit_authorName to your own name. OK. The standard format code is commented out.

5) a. vim. cpp and. h file Quick Switch

Put downloaded a. vim under plugin without configuration.

You can directly: A, open the file. cpp and. h corresponding to: AV, open the file. cpp and. h, and split the screen, as shown below:

OK. If you have configured vim according to my instructions, your vim should be a super powerful IDE.

 

 

Transferred from: www.vimer.cn

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.