Pomme-c-vim can build a vim-plugin-based environment for c/c++. It will install and configure the YouCompleteMe and some other plugins.
It allows you to search and replace words, comment and uncomment codes.
It allows you to jump to header file, to declaration and to definition recusively.
It allows you to create files with templates.
It allows you to format codes with K&R style.
Execute ./check.sh
to check if the environment is suitable for the installation.
Execute ./install.sh
to do the installation.
a) Downloading clang may fail while installing YCM. In this case, you need to download clang (libclang-7.0.0-x86_64-unknown-linux-gnu.tar.bz2
for x86_64) manually from https://dl.bintray.com/micbou/libclang/ and put it into ~/.vim/bundle/YouCompleteMe/third_party/ycmd/clang_archives/
, then execute ./install_YCM.sh && vim -E -c PluginInstall -c q -c q
to finish the installation.
b) Omnisharp for c# may fail on downloading for some reason. This error can be ignored if you don't use c#. Otherwise, you can manually download it from https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v1.32.19/omnisharp.http-linux-x64.tar.gz and move it into ~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/omnisharp-roslyn/v1.32.19/
, then execute ./install_YCM.sh && vim -E -c PluginInstall -c q -c q
to finish the installation.
c) On Mac OS, you need to install ctags
with brew
with the command: brew install ctags
, and then add alias ctags="`brew --prefix`/bin/ctags"
into the ~/.bashrc
.
Execute source ~/.bashrc
after the installation to make vimc
work.
To start a C/C++ project, execute vimc
at the root of the project.
Why "at the root of project"? To ensure that searching, jumping and formatting in the project works as expected with the help of .ycm_extra_conf.py
, .tags
and .clang-format
generated by executing vimc
.
:Q<CR>
: quit vim and all plugins, delete .ycm_extra_conf.py
, .clang-format
and .tags
in the root of project
:W<CR>
: save all
\tg
: open or close the window of taglist
<F5>
: go to shell, equivalent to :sh<CR>
<F6>
: format the current file with K&R style
mh
: move cursor to left window
mj
: move cursor to bottom window
mk
: move cursor to top window
ml
: move cursor to right window
mw
: move cursor to window below/right of the current one
mt
: move cursor to top-left window
mb
: move cursor to bottom-right window
mp
: move cursor to previous window
<C-j>
: switch current line with next line
<C-k>
: switch current line with previous line
\cc
: comment one line
\cv
: comment one line with next delimiter
\cm
: comment multi lines
\c$
: comment to end of line
\cu
: uncomment
<C-p>
: search file in project
:Grep [keyword]
: search the keyword in project
\vv
: search the word under cursor in project
\vr
: replace the word under cursor in project (:ReplaceUndo
to undo the replace)
cgt
: save changes and close all tabs except the first, then close the bottom-right window
:ccl<CR>
: close Grep
window
<F12>
: jump to header file
<C-]>
: jump to declaration or to definition
g<C-]>
: jump to the only match or list multi matches
<C-o>
: go backword
<C-i>
: go forward
To get more information about usage, click on the links at the References below.
- Edit the line 59 to 61 of
ycm_extra_conf.py
to change the searching path of YCM. - Edit the template files at
~/.vim/templates/
to customize the templates for.h
,.hpp
,.c
and.cpp
. <C-]>
is set as2<C-]>
in.vim
files, because the second option is normally what you need. If not, typeg<C-]>
then a number to do your choice.- For huge/distributed projects, use
<F12>
before<C-]>
is recommended if possible. - If
tags file not ready
is printed while typing<C-]>
org<C-]>
, it means that the file.tags
hasn't been generated yet byctags
. It is probably because that the project is so huge thatctags
needs some time to generate the.tags
. - After typing
C-p
and selecting a file, typeF12
is recommanded to refresh the Nerdtree. :help syntastic_quiet_messages
to avoid unexpected error messages from syntastic.<C-l>
may be necessary to refresh the whole vim interface after some operations, such as<F6>
.
Custom names aren't recommended to use the used words in C++ Standard Library and in STL. So words like count
from int count;
would be highlighted as it is the function name coming from STL. If you want to get a custom name like count
without highlight, you need to replace the line systax keyword cppSTLfunction count
into syntax match cppSTLfunction "\(\.|-\>\)\@<=count"
in the file cpp.vim
in ~/.vim/after/syntax/
.
The syntax highlight works based on the regular experssion. So long codes in one line may cause delay. To avoid this, the syntax highlight works on the lines with the length smaller than 600, the part of over 600 won't be highlighted.
https://github.com/VundleVim/Vundle.vim
https://github.com/Valloric/YouCompleteMe
https://github.com/rdnetto/YCM-Generator
https://github.com/tpope/vim-pathogen
https://github.com/scrooloose/nerdtree
https://github.com/vim-syntastic/syntastic
https://github.com/dkprice/vim-easygrep
https://github.com/ctrlpvim/ctrlp.vim
https://github.com/scrooloose/nerdcommenter
https://github.com/vim-scripts/taglist.vim
https://github.com/rstacruz/sparkup
https://github.com/tpope/vim-fugitive
https://github.com/Yggdroot/indentLine
https://github.com/tomasiser/vim-code-dark