Skip to content

YvesZHI/Camel-vim

Repository files navigation

Camel-vim

Switch to the branch vim8 if the version of your vim is 8 or higher is highly recommended.

Introduction

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.

Tested OS list

Ubuntu 16.04
Ubuntu 18.04

Installation

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.

Issues

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.

General Usage

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.

Normal Mode

: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

Insert Mode

<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.

Tips

  1. Edit the line 59 to 61 of ycm_extra_conf.py to change the searching path of YCM.
  2. :YcmGenerateConfig has been executed automatically while enterning vim, it enables "goto declaration or definition" if Makefile or CMakeLists.txt is used. Re-execute it if necessary.
  3. Edit the template files at ~/.vim/templates/ to customize the templates for .h, .hpp, .c and .cpp.
  4. <C-]> is set as 2<C-]> in .vim files, because the second option is normally what you need. If not, type g<C-]> then a number to do your choice.
  5. For huge/distributed projects, use <F12> before <C-]> is recommended if possible.
  6. If tags file not ready is printed while typing <C-]> or g<C-]>, it means that the file .tags hasn't been generated yet by ctags. It is probably because that the project is so huge that ctags needs some time to generate the .tags.
  7. After typing C-p and selecting a file, type F12 is recommanded to refresh the Nerdtree.
  8. :help syntastic_quiet_messages to avoid unexpected error messages from syntastic.
  9. <C-l> may be necessary to refresh the whole vim interface after some operations, such as <F6>.
  10. vim -Nu ~/.vim/bundle/YouCompleteMe/vimrc_ycm_minimal xxx.cpp to get minimal vim configuration for YCM to debug YCM.
  11. Debug commands of YCM: :YcmDiags, YcmDebugInfo, YcmToggleLogs.

C-family Semantic Completion Engine

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 ../.

About syntax highlight

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.

USE YCM SYNTAX CHECKER INSTEAD OF SYNTASTIC IS RECOMMENDED --- NOT FINISHED YET

References

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

About

Build a C/C++ vim-based development environment.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published