Original [YCM] Youcompleteme Installation Complete Guide

Source: Internet
Author: User
Tags autoload

Because there is really no bird ctags: There are many classes in the code that have the same name, such as "id". When I want to see the current "id" in the end is which ID of the time, terrible things thick line,,, a breath out of 10 several alternatives. And, can't jump to local variables, the completion is not accurate,,,,,,,,,,, I finally decided to toss a youcompleteme (YCM).

First of all, a brief introduction of the landlord's development environment: a Windows PC can connect with the outside network, an intranet server development machine (64-bit REDHAT6, this server can not connect the network). Usually move bricks with the PC SSH to the server, directly on the server with VIM code brick.

Online introduction YCM installation of the Raiders are also many, but they are not suitable for my current situation. So decided to nibble on official website documents. After all, this is always the most accurate and detailed. Official website See: Https://github.com/Valloric/YouCompleteMe#commands

Although there is a section on the official website that says "Quick Install", the author says "It doesn't necessarily apply to your environment". I do not think my environment can be implemented successfully, simply follow the full installation guide.

The first step is to upgrade vim.

YCM requires a vim version of 7.3 or more, and the version of my development machine is 7.0. orz~~. In addition, do not expect 0 pain in the intranet Yum source. In addition, I do not want to compile vim from the source code (although YCM's author said a "Don t worry, it's easy" ~ ~). Then began to find vim on the goooogle RPM package. So here's the question, how many RPM packages do you need? Use this command on the development machine: RPM-QA | grep vim, found with four packages: Vim-common, vim-enhanced, Vim-minimal, Vim-filesystem.

Fortunately, the company can directly on the goooogle, direct Google "vim rpm" to find such a website: https://www.rpmfind.net/linux/rpm2html/search.php. Then in here to search each of these bags, this site will be all the distribution of RPM packages are listed, for my 64-bit redhat6, to select the el6_x86_64 suffix package. Download them to the PC, then the RZ command to the development machine, install it. Before installing, remove the previous vim package. Then OK, to a 7.4 version of Vim. (The process is not the understatement of the two sentences to take care of, at least I have so-called "Unix philosophy" fuck 100 times,,,,).

  

Step two, download ycm.

Online all the Raiders say, through Vundle to download ycm. However, I am an intranet machine ah Ah ah, and can not use Vundle. I also try to get an HTTP proxy on my PC and then let the developer access the extranet via the PC's proxy. However, the links on GitHub are Https~~~~~orz, and the dogs are on the day. Carefully observe the directory structure of the next ycm, found that is, and a common vim plug-in almost ~ ~ so on the PC git clone, and then hit a zip package, and then RZ to the development machine. And so on, there is one sentence on the document: If you do not install YCM with Vundle, makes sure you has run after git submodule update --init --recursive checking out the YCM repository ( Vundle would do this for you) to fetch YCM ' s dependencies. OK, first execute the git submodule update--init--recursive, and then pack the pass. found that the command after the execution, more than a lot of things. These things are used in the back.

Unzip the zip package to the ~/.vim/bundle/youcompleteme directory.

  

Step three, install clang.

YCM is also based on the clang complement. Installation of clang is certainly necessary. Look for clang rpm packages on Google, similar to the way you install VIM. The main is clang-3.4.2-4.el6.x86_64.rpm, llvm-3.4.2-4.el6.x86_64.rpm, llvm-libs-3.4.2-4.el6.x86_64.rpm three of these bags. Here is a very important, is the 64-bit system, be sure to install x86_64 package. At the beginning of the installation of the wrong, clang installed i686 bag (i686 is actually 32-bit), although clang can be used normally, but ycm compile C + + engine will be a cup.

  

Fourth step, install CMake.

The Yum source of the intranet has finally had a bit of a role. The direct yum install CMake is installed successfully.

  

Fifth step, compile the C + + engine (ycm_support_lib).

If it's not used to complete C + +, then this step can be skipped. Start by creating a Ycm_build directory (anywhere you want.) This is just a temporary directory. Then CD Ycm_build, then execute

Cmake-g "Unix makefiles"-duse_system_libclang=on. ~/.vim/bundle/youcompleteme/third_party/ycmd/cpp

Since I am using the clang of the system, I will use-duse_system_libclang=on.

At this time you can see the Ycm_build directory more out of a pile of things.

And then executecmake --build . --target ycm_support_libs. 

If this step is smooth, it would be great.

The first time you try without adding-duse_system_libclang=on, compiling and compiling fails.

The second time, add the-duse_system_libclang=on, execution to 91%, or error, and later found that clang installed a 32-bit version,,,

Finally compiled through, at this time, you can see the ~/.vim/bundle/youcompleteme/third_party/ycmd directory more than a ycm_client_support.so and ycm_core.so, This should be the compiled C + + engine.

  

Sixth step to make ycm effective

YCM need a file called. ycm_extra_conf.py as the ycm "entrance". When you start vim, you look for the file and then load it (from the current directory to the top). The main meaning of this file is to allow clang to "compile" the current source file. Because YCM is based on semantic completion, the. CPP is parsed and semantically analyzed. So you have to tell clang some specific compiler parameters (the more important is-I, let clang know which directories to your change files). If clang cannot compile the. cpp correctly, then many of the completion functions will fail. The: Ycmdiags command lets you see what compilation errors are in the current file. This file has two main parts: one is the flags array, in which is the compile option. One is Compilation_database_folder. This compilation_database_folder is a feature that relies on clang. Clang can export a database at compile time and then use this compilation_database_folder to load the clang database to get the most accurate and complete completion and jump. Since our code is GCC-compiled (it is believed that there are few projects compiled with Clang), there is no database to export, only flags. (These two things are two to one.) If you have a database, read the database first, and then go to the flags.

The reference template modifies the flags (mainly by adding several-I, because our code refers to many of the company's internal library header files, so that clang can find the location of the header files).

Official web Guide, the last step is gone. However, this time ycm did not take effect. Try to copy the Youcompleteme.vim under the Autoload/youcompleteme.vim and plugin directories under the Youcomplete directory to ~/.vim autoload and plugin, which finally responds, But the error said that can not find ycm_core.so. Open Youcompleteme.vim, find inside in try from. /third_party/ycmd and. /python to find the content. The Python and Third_party directories under the ~/.vim/bundle/youcompleteme/are then copied to the ~/.vim directory.

At this time, YCM can finally use. Wrote a test.cpp, a simple test, whether it is complete and jump, are very strong, fully in line with their expectations. In addition, YCM also has the function of grammar check, but I think the error mark is too ugly, it is turned off (let g:ycm_enable_diagnostic_signs = 0).

Then very happy with the company project source test under,, immediately face a black,,, Unicodedecodeerror: ' UTF8 ' codec can ' t decode byte 0xcd in position 0:invalid continua tion byte. Repeatedly reported this error, ycm all kinds of functions are completely wood. T_t immediately feel hard 20 years, one night back to liberation. Careful analysis of the next, is it the source of the Chinese is the GBK format caused? So a CPP into the UTF8 format, and then try again, sure enough ycm and can use. NM, this How to do, should the company's source code are made into UTF8? This is unscientific. Decisive first to Goooogle, found that someone has encountered this problem: https://github.com/Valloric/YouCompleteMe/issues/1458 ycm author in another post (https:// github.com/valloric/youcompleteme/issues/1378) In this reply, "This might being related to whatever is set as your the current file encod ing in Vim ". Seems to guess good, after all, the author is crooked Nuts, why let others support GBK?

But after all, is open source project, the biggest advantage is can see the source code, and can go to modify ~ ~ So decided to change the source to let YCM support GBK. First Use this command: Ycmdebuginfo, you can see the error details:

Traceback (most recent): File"<string>", Line 1,inch<module>File"/root/.vim/autoload/. /python/ycm/youcompleteme.py", Line 526,inchDebuginfo'Debug_info') File"/root/.vim/autoload/. /python/ycm/client/base_request.py", line 71,inchpostdatatohandler Timeout)) File"/root/.vim/autoload/. /python/ycm/client/base_request.py", line 166,inchjsonfromfutureRaisemakeserverexception (Response.json ()) Ycmd.responses.ServerError:UnicodeDecodeError:'UTF8'Codec can'T decode byte 0xc1 in position 0:invalid start byteE858:eval did not returnA valid Python object

Each file opens and looks, and the last location to the problem may appear here:

/root/.vim/third_party/ycmd/ycmd/utils.py, there is a RecursiveEncodeUnicodeToUtf8 function in it. This function probably means to change the source code file into UTF8 format, and then follow the UTF8 format decode. If there is a problem with this step, then the decode will definitely go wrong. The function is then modified to look like this:

defRecursiveEncodeUnicodeToUtf8 (value):ifisinstance (value, Unicode):returnValue.encode ('UTF8' )  ifisinstance (value, str):Try: Value= Value.decode ('GBK'). Encode ('UTF8')    exceptunicodedecodeerror,e:Pass    returnvalueelifisinstance (Value, collections. Mapping):returndict (Map (RecursiveEncodeUnicodeToUtf8, Value.iteritems ()))elifisinstance (Value, collections. iterable):returntype (value) (Map (RecursiveEncodeUnicodeToUtf8, value))Else:    returnValue

Mainly for if isinstance (value, str): Branch modification. It was preceded by a direct return of value. This means that returning a string in the GBK format, and then pressing UTF8 to parse it, will definitely be wrong. So this value first press GBK decode, and then encode into UTF8. Then, the problem is solved!!

At this point, ycm really can use!

The effect did explode ctags several streets, not in vain I so laborious toss.

Finally put on my ycm configuration:

Let g:ycm_global_ycm_extra_conf ='/search/odin/code/.ycm_extra_conf.py'Let g:ycm_confirm_extra_conf=0 Let G:ycm_key_invoke_completion='<C-i>'Set completeopt=Longest,menuautocmd Insertleave*ifPumvisible () = = 0|pclose|Endifinoremap<expr> <CR> pumvisible ()?"\<c-y>":"\<cr>"Let g:ycm_enable_diagnostic_signs=0 Let G:ycm_enable_diagnostic_highlighting= 1Let g:ycm_collect_identifiers_from_comments_and_strings=0 Let G:ycm_complete_in_comments=0 Let G:ycm_complete_in_strings=0 Let G:ycm_min_num_of_chars_for_completion= 2

More options can be found in the option section on the official website.

Summarize

Google is a lot more than Baidu. No Google absolutely no play.

Chew the document carefully, there are many problems encountered, there are mentions in the document.

Original [YCM] Youcompleteme Installation Complete Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.