I always want imporve my skills on VIM. Thus recently I spent two days on setting up a VIM IDE for C/C++ proprogramming. Below are some useful steps for YCM.
Specifications
Mac Info
OS X Yosemite
Version 10.10.5
VIM
Mac OS Unix Version (MacVIM)
Vi Improved 8.0
And I also have installed HomeBrew for Mac and Vundle for Vim plugins management.
Latest MacVim
First make sure you have HomeBrew in your computer, because it is a great tool to install some missing packages and tools in Mac OS.
You always want to install the lates MacVim, which is required by Youcompleteme. In your terminal, run:
brew update
brew install vim && brew instal macvim
brew link macvim
You should now be able to launch MacVIM from the terminal using mvim
.
Install YCM using Vundle
The following steps are according to the instruction in Github.
Note: I saw in the installation section that you can install it in a ideal way or following the full guidance. I tried the ideal way, but reality turned out never to be ideal. SO please follow the full guidance. It will help you understand what is going on inside YCM.
To use Vundle for installation, put the following line in your .vimrc
configuration file:
Plugin 'valloric/youcompleteme'
And then run PluginInstall
in your VIM commandline. It should work just fine.
Install CMake using Brew
CMake is a helpful tool to compile the source file, and is also suggested in the full guidance. A easy way to install it is using HomeBrew. Run these:
brew install cmake
Just for synchronization, if you type in the terminal cmake
, you should get the usage info for the function.
Download and extract libclang for C/C++ semantic completion
This is an important step to make sure that your YCM will be powered to do semantic completion for the specific languages.
Here comes HomeBrew again. Run brew install llvm
will download and extract the libclang for you. Wait a minute when the process is done. Take a look at the return information, which tells you the location of the extrated files. Take note and you'll need it afterwards ! For me, my llvm
folder locates at /usr/local/opt/llvm
.
Compile YCM
Excitingly, we are now good to compile the ycm_core
library. Please refer to more information in instruction in Github.
First, confirm that where your youcompleteme
folder locates, ~/.vim/bundle/youcompleteme
for me.
Then, prepare for building files. In the terminal:
cd ~
mkdir ycm_build
cd ycm_build
Since I DO care about semantic support for C-family (Hey, can anyone tell me what languages the 'C-family' actually includes ???), make sure that you have your extracted files located at the right place. In the terminal:
cp -R /usr/local/opt/llvm ~/ycm_temp
mv ~/ycm_temp/llvm ~/ycm_temp/llvm_root_dir
Now you should have the directorie at the right location. To assure you, the directory, llvm_root_dir, has something like bin
, lib
, and include
etc, and now you have two filders named ycm_build
and ycm_temp
under ~/
.
Inside the ycm_build
directory, run in the terminal:
cd ~/ycm_build
cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/ycm_temp/llvm_root_dir . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
sudo cmake --build . --target ycm_core --config Release
"Unix Makefiles" is a generator tag. If you want to know more, please refer to instruction in Github.
Extra files to configure
Good luck to you if you don't have any errors. Now your YCM is supposed to work. But before we finish, we need to configure an extra file.
You can consider using YCM-Generator to generate the need file, accoding to the doc.
If you don't want to bother with it, simply copy this file, put it at ~/.vim/.ycm_extra_conf.py
', and lastly put let g:ycm_global_ycm_extra_conf = "~/.vim/.ycm_extra_conf.py"
in your .vimrc
.
YCM will recersively find the closest extra conf file, starting from the current location.
Congratulations, your YCM should work just fine.
Python quit unexpectedly every time I launch my MacVIM
This is probably you have linked YCM and MacVIM to different python. Try this:
cd /usr/local/Frameworks/Python.framework/Versions/2.7
cp Python Python_bak
cd /System/Library/Framework/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS
sudo cp Python Python_bak
ln -sf Python /usr/local/Framework/Python.framework/Versions/2.7/Python
To be continued
The actual efficiency needs to be tested, since I just finished the configuration myself.
How to generate personalized extra conf file.
9/25/2016
Weiming
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。