Camel-vim can build a vim-plugin-based environment for c/c++. It will install and configure 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.
Ubuntu 16.04
Ubuntu 18.04
Camel-vim supports vim 7 and vim 8. The branch master is for vim 7 and the branch vim8 is for vim 8.
Execute ./check.sh
to check if the environment is suitable for the installation.
Execute ./install.sh
to do the installation.
a) YouCompleteMe may have many issues. If there are some failures about it, try to reinstall it and execute ./install_YCM.sh
manually. Here are two examples:
- 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
to finish the installation. - 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
to finish the installation.
b) 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 & :Q<CR>
<C-k>
: save
\tg
: open or close the window of taglist
<F5>
: go to shell, equivalent to :sh<CR>
gg=G
: format the current file with K&R style with the tool clang-format
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
+
: increase width of window towards left
-
: decrease width of window towards right
\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]<CR>
: search the keyword in project
\vv
: search the word under cursor in project
:Replace [keyword]<CR>
: replace the word under cursor with keyword
in project
:Replace [target] [keyword]<CR>
: replace the word target
with keyword
in project
:UndoReplace<CR>
: undo :Replace
cgt
: save changes and close all tabs except the first, then close the bottom-right window
:ccl<CR>
: close Grep
window
\'
: wrap selected part by "'", if no part is selected, the word under cursor will be wrapped
\\'
: remove the closest "'" wrapped the part in which the cursor is
similar shortcuts: \"
and \\"
, \(
and \\(
, \[
and \\[
, \{
and \\{
, \<
and \\<
<F12>
: goto header file
<C-]>
: goto declaration or to definition
g<C-]>
: goto the only match or list multi matches
<C-o>
: go backword
<C-i>
: go forward
:ConqueGdb<CR>
: run ConqueGdb
<C-j>
: move cursor backwards out of parenthesis
<C-k>
: goto normal mode and save
<C-e>
: move the current character to the end of next word
<C-l>
: move the cursor to the end of line
<C-\>
: delete the word under the cursor
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. :YcmGenerateConfig
has been executed automatically while enterning vim, it enables "goto declaration or definition" ifMakefile
orCMakeLists.txt
is used. Re-execute it if necessary.- 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>
.vim -Nu ~/.vim/bundle/YouCompleteMe/vimrc_ycm_minimal xxx.cpp
to get minimal vim configuration for YCM to debug YCM.- Debug commands of YCM:
:YcmDiags
,YcmDebugInfo
,YcmToggleLogs
.
As YCM doc mentioned, we can have two choices to enable this important function: compile_commands.json
or .ycm_extra_conf.py
. The first one always has the better performance so we pick it. Read this link about how to generate the file compile_commands.json
: https://github.com/MaskRay/ccls/wiki/Project-Setup. You just need to add a flag while executing cmake ../
in your directory build
: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES ../
.
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/preservim/nerdtree
https://github.com/vim-syntastic/syntastic
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/Yggdroot/indentLine
https://github.com/jiangmiao/auto-pairs
https://github.com/tpope/vim-repeat
https://github.com/tpope/vim-fugitive
https://github.com/Xuyuanp/nerdtree-git-plugin
https://github.com/YvesZHI/vim-code-dark
https://github.com/YvesZHI/vim-cpp-enhanced-highlight
https://github.com/vim-scripts/Conque-GDB
https://codeyarns.com/2015/03/18/how-to-test-color-setup-in-vim