is great feature for programmers who work on various types of programming languages like the C/C + + languages. Vim editor
provides this feature under Windows
. The autocompletion
of C/C + + in Vim
searches for words that are typed in from a file that has previously saved its tags
in it. The user, with help of the hardware component of the system - i.e. the keyboard, will configure a key
to jumpstart the process of looking through the stored tags. However, it would be prudent to keep an eye open for any words that do not make sense.
This tutorial is aimed at people running Vim on Linux. Auto-complete is a familiar function to Linux users, however it can sometimes suggest words that do not make sense in context. This can be frustrating when programming, as Auto-complete may suggest, for example, a type when a method is expected at that point in the code.
p. // <-- Ctrl P proposera successivement : plopez, plop... alors que c'est forcément plopons
A plugin, based on ctags Vim enables you to create a more intelligent Auto-complete that can take into account the context in which a word is used.
We begin by installing ctags. For example, under Debian or Debian based distributions (ubuntu, xandros etc.):
sudo aptitude update
sudo aptitude safe-upgrade
sudo aptitude install exuberant-ctags
It also recovers the Vim plugin for auto-completion:
We will do everything regarding self-completion in ~ /. Vim:
mkdir -p ~/.vim/tags
mv omnicpp*zip ~/.vim
Ctags is able to consider the problem of headers QT, OpenGL, SDL. However, for the STL, you must retrieve headers "simple" here:
It unpacks the archive and creates tags from the STL:
tar xjvf cpp_src.tar.bz2
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ cpp_src && mv tags ~/.vim/tags/stl
Now it generates the tags for the libraries installed (to be adapted if the libraries are installed elsewhere). For example, in the libraries OpenGL, SDL and QT, simply type the following three commands:
tags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ /usr/include/GL/ && mv tags ~/.vim/tags/gl
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ /usr/include/SDL/ && mv tags ~/.vim/tags/sdl
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ /usr/include/qt4/ && mv tags ~/.vim/tags/qt4
Now we must tell vim to load the plugin files and the different tags. To do this, simply add to the end of the file ~ /. Vimrc the following lines:
" prérequis tags
filetype plugin on
" configure tags - add additional tags here or comment out not-used ones
" build tags of your own project with CTRL+F12
"map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
noremap <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>
inoremap <F12> <Esc>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_MayCompleteDot = 1
let OmniCpp_MayCompleteArrow = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
If tags were only generated for some files, comment on the other by adding to the beginning of the line. For example if we have not generated ~ /.vim/tags/gl and ~ / .vim/tags/sdl:
We just have to save the file and (re) start vim so that they reflect changes to ~ /. Vimrc.
Everything that has been previously tagged (ie in this tutorial tags STL, QT, SDL, and OpenGL) is already available in the auto completion. Simply press ctrl p or n. Once the list appears, you can use the arrows to highlight the good proposal and press enter.
However, it is not completely finished. It should regenerate the tags of symbols (variables, functions, types ...) specific to the project that is being developed. This will once again generate a tags file. And of course, it will refresh the file every time you add, delete or change a symbol of the project so that it is current.
As is quite common, it is recommended that you map a key on the keyboard to trigger a process of ctags. In the example file ~/.Vimrc that I gave, this is ensured by pressing F12.