Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install the vim YouCompleteMe auto-completion plug-in in ubuntu14.04

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces ubuntu14.04 how to install the vim YouCompleteMe automatic completion plug-in, the article is very detailed, has a certain reference value, interested friends must read it!

1, system environment check!

Ubuntu 14.04.5 LTS, 64-bit system and kernel version: chunli@Linux:~$ lsb_release-aNo LSB modules are available.Distributor ID: UbuntuDescription: Ubuntu 14.04.5 LTSRelease: 14.04Codename: trustychunli@Linux:~$ uname-rm4.4.0-31-generic x86

Don't look down if the environment doesn't match.

Install system compilation tools, dependent header files, libraries

1. Install the compilation tool root@Linux:~# apt-get install build-essential2, install the dependent header file and library root@Linux:~# apt-get install python-dev python3-dev3 My cmake version is too low to compile libclang requires a high version of cmake 3.4.3 or higher root@Linux:# apt-get-y autoremove cmake # uninstall the old version of cmakeroot@Linux:~# wget https://cmake.org/files/v3.8/cmake-3.8.0-rc2.tar.gzroot@Linux:~# tar xf cmake-3.8.0-rc2.tar.gz root@Linux:~# cd cmake-3.8.0-rc2/root@Linux:~ / cmake-3.8.0-rc2#. / bootstrap & & make & & make installroot@Linux:~/cmake-3.8.0-rc2# echo $? 0 verify the installation of cmake root@Linux:~/cmake-3.8.0-rc2# cmakebash: / usr/bin/cmake: there is no file or directory to find a new cmake path root@Linux:~/cmake-3.8.0-rc2# which cmake/usr/local/bin/cmake to create a soft link Root@Linux:~/cmake-3.8.0-rc2# ln-s / usr/local/bin/cmake / usr/bin/cmake check the current version of cmake root@Linux:~/cmake-3.8.0-rc2# cmake--versioncmake version 3.8.0-rc2 so that the compilation tool is complete

Compile and install vim 8.0

Ubuntu source code compilation and installation of the latest vim 8.0

3. Get the YouCompleteMe,Vundle software package

Root@Linux:~# git clone https://github.com/Valloric/YouCompleteMe.git ~ / .vim / bundle/YouCompleteMeroot@Linux:~# git clone https://github.com/VundleVim/Vundle.vim.git ~ / .vim / bundle/Vundle.vim/bundle/Vundleroot@Linux:~# vim ~ / .vimrc adds the following line: filetype off set rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin () Plugin 'VundleVim/Vundle.vim'Plugin 'Valloric/YouCompleteMe'call vundle#end () filetype plugin indent on root@Linux:~# installs the vim plug-in root@Linux:~# vim + PluginInstall + qallroot@Linux:~# echo $? 0

Download, compile and install libclang source code

The libclang library it provides is used to power the YCM semantic completion engine for those languages. YCM is designed to work with libclang version 3.9 or higher. Official website http://releases.llvm.org/download.html official documentation, it is worth seeing: http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summaryclang is the C of llvm project, C++ Objective C and Objective C++ front-end Compiler-RT mainly provides runtime library support for Clang and LLVM, root@Linux:~# wget http://releases.llvm.org/3.9.1/llvm-3.9.1.src.tar.xzroot@Linux:~# wget http://releases.llvm.org/3.9.1/cfe-3.9.1.src.tar.xzroot@Linux:~# wget http://releases.llvm.org/3.9.1/compiler -rt-3.9.1.src.tar.xzroot@Linux:~# tar xf cfe-3.9.1.src.tar.xz root@Linux:~# tar xf llvm-3.9.1.src.tar.xz root@Linux:~# tar xf compiler-rt-3.9.1.src.tar.xz root@Linux:~# mv cfe-3.9.1.src llvm-3.9.1.src/tools/clangroot@Linux:~# mv compiler-rt-3.9 .1.src llvm-3.9.1.src/projects/compiler-rtroot@Linux:~# mkdir binroot@Linux:~# cd bin/2 Generate the Makefile file root@Linux:~/bin# cmake-G "Unix Makefiles".. / llvm-3.9.1.srcroot@Linux:~/bin# echo $? 03, compile and install root@Linux:~/bin# make & & make installroot@Linux:~/bin# echo $? 0mura-[compilation instructions] (1). This make does not specify multitasking. Because when connecting to the library later, multitasking will lead to memory overflow, and the kernel will kill the ld process make single process. Although it is a bit slow, it will not cause make-j 8 to be posted at the end of the error article. When the ld occupies memory and the parameters of the ld program are posted, shout! (2) the disk space must be large enough. Look at this guy after the compilation. How big the package is! root@Linux:~# du-sh llvm-3.9.1.src357M llvm-3.9.1.srcroot@Linux:~# du-sh bin/25G bin/root@Linux:~#-finally compiled and installed Post compilation time root@Linux:~/bin# export HISTTIMEFORMAT= "% F [% T]" root@Linux:~/bin# history | grep-A 8 'mkdir bin' 2017-03-04 [17:16:45] mkdir bin# starts preparing 688 2017-03-04 [17:16:59] cd bin/ 2017-03-04 [17:17:31] cmake-G "Unix Makefiles".. / llvm-3.9 .1.src 2017-03-04 [17:18:23] echo $? 691 2017-03-04 [17:19:01] make-j 8 & & make install # later reported an error Memory overflow 2017-03-04 [19:38:10] make & & make install # change order process immediately 693 2017-03-04 [20:24:17] echo $? # at this time Compilation completed 694 2017-03-04 [20:24:56] export HISTTIMEFORMAT= "% F [% T]" 695 2017-03-04 [20:25:03] history-- Test clang root@Linux:~/bin# clang--helpOVERVIEW: clang LLVM compilerUSAGE: clang-3.9 [options] so that clang is Installation completed to find the libclang.so installation path Useful later! root@Linux:/# find /-name'* libclang.so'/usr/local/lib/libclang.so/home/chunli/bin/lib/libclang.so

Compiling, configuring YouCompleteMe

[description] I am a Linux C programmer, need to use C family syntax automatic completion using my custom libclang.so-DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so [compile] root@Linux:~$ cd ~ root@Linux:~$ mkdir ycm_buildroot@Linux:~$ cd ycm_buildroot@Linux:~/ycm_build# cmake-G "Unix Makefiles"\ # turn on the command line feed mode-DEXTERNAL_LIBCLANG_PATH=/usr/local/lib/libclang.so. \ ~ / .vim/bundle/YouCompleteMe/third_party/ycmd/cpproot@Linux:~/ycm_build# echo $? 0root@Linux:~/ycm_build# cmake-build. -- target ycm_core-- config Releaseroot@Linux:~/ycm_build# echo $? 0 configure YouCompleteMeroot@Linux:~/ycm_build# cp ~ / .vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py ~ / .vim / chunli@Linux:~$ cat ~ / .vimrc # add two lines of let g:ycm_server_python_interpreter='/usr/bin/python'let GRV

An improved vim configuration file is attached, which can be directly replaced by ~ / .vimrc

Chunli@Linux:~$ cat ~ / .vimrcset bg=dark "Black background set completeopt=menu" turn off draft set nu "Show line number set paste" do not automatically indent set scrolloff=5 "cursor to upper and lower buffer margin set nobackup" prohibit generation of temporary files set nocindent "do not use C style indent set noautoindent" do not use from Dynamic indent set shiftwidth=4 "automatically indent character width set ts=4" tab key width set expandtab "convert tab character to space% retab! "for saved files, ignore case syntax on" syntax highlight set hls "search highlight set bg=dark" font highlight set nocompatible when performing expandtabset fencs=utf-8,ucs-bom,shift-jis,GB2312,GBK,gb18030,gbk,gb2312,cp936 "supported character set set ignorecase" search to remove compatibility viset backspace=indent,eol Start "allows the use of the Backspace key" vim color match related "colorscheme corporationcolorscheme solarized" colorscheme molokai "YouCompleteMe configuration related let g:ycm_server_python_interpreter='/usr/bin/python'let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'filetype off set rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin () Plugin 'VundleVim/Vundle.vim'Plugin' Valloric/YouCompleteMe'call vundle#end () filetype plugin indent on" vim Set shortcut mode 1 F2-> define F3-> declar F4-> autolet g:ycm_goto_buffer_command = 'new-tab'' jump open new screen "let g:ycm_goto_buffer_command = 'horizontal-split'" jump open upper and lower split screen map: YcmCompleter GoToDefinition map: YcmCompleter GoToDeclarationmap: YcmCompleter GoToDefinitionElseDeclaration "vim setting shortcut key mode 2" let g:ycm_goto_buffer_command =' horizontal-vsplit' "jump open new split screen: e# exit split screen "let mapleader ='\'" command mode \ df jumps to definition,\ dc jumps to declaration,\ de arbitrarily looks for "nnoremap df: YcmCompleter GoToDefinition" nnoremap de: YcmCompleter GoToDeclaration "nnoremap dc: YcmCompleter GoToDefinitionElseDeclarationchunli@Linux:~$

Attached is an improved. Ycm_extra_conf.py configuration file, which can directly replace ycm_extra_conf.py

Root@Linux:~# cat / .vim/.ycm_extra_conf.py# Copyright (C) 2014 Google Inc.## This file is part of ycmd.## ycmd is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## ycmd is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with ycmd. If not, see. Import osimport ycm_core# These are the compilation flags that will be used in case there's no# compilation database set (by default, one is not set). # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.flags = ['- Wall','-Wextra','-Werror','-fexceptions','-DNDEBUG',# THIS IS IMPORTANT! Without a "- std=" flag, clang won't know which# language to use when compiling headers. So it will guess. Badly. So Cellular # headers will be compiled as C headers. You don't want that so ALWAYS specify# a "- std=". # For a C project, you would set this to something like 'c99' instead of# 'cantilever 11. And the same thing goes for the magic-x option which specifies the# language that the files to be compiled are written in. This is mostly# relevant for C++ headers.# For a C project, you would set this to 'c' instead of 'cantilevered telegrapher, you would set this to' c'mai 'pyrus, etc., etc., in this case, we know that it is possible to use a variety of tools such as XcodeDefault.xctoolchainAccording to the development of toolchainsand XcodeDefault.xctoolchainCPUSCUBING. # add_by_chunli date:2017.03.05 00RV 20 quotation isystemwise, cinematopoeia, cinematography, cinematology, cinnabar, etc.] # Set this to the absolute path to the folder (NOT the file!) Containing the# compile_commands.json file to use that instead of 'flags'. See here for# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html## Most projects will NOT need to set this to anything You can just change the# 'flags' list of compilation flags.compilation_database_folder =''if os.path.exists (compilation_database_folder): database = ycm_core.CompilationDatabase (compilation_database_folder) else: database = NoneSOURCE_EXTENSIONS = ['.cpp', '.cxx', '.cc','.c','.m' '.mm'] def DirectoryOfThisScript (): return os.path.dirname (os.path.abspath (_ _ file__)) def MakeRelativePathsInFlagsAbsolute (flags, working_directory): if not working_directory: return list (flags) new_flags = [] make_next_absolute = False path_flags = ['-isystem','- iTunes,'- iquote' '--sysroot='] for flag in flags: new_flag = flag if make_next_absolute: make_next_absolute = False if not flag.startswith (' /'): new_flag = os.path.join (working_directory Flag) for path_flag in path_flags: if flag = = path_flag: make_next_absolute = True break if flag.startswith (path_flag): path = flag [len (path_flag):] new_flag = path_flag + os.path.join (working_directory) Path) break if new_flag: new_flags.append (new_flag) return new_flagsdef IsHeaderFile (filename): extension = os.path.splitext (filename) [1] return extension in ['.h', '.hxx', '.hpp', '.hh'] def GetCompilationInfoForFile (filename): # The compilation_commands.json file generated by CMake does not have entries # for header files. So we do our best by asking the db for flags for a # corresponding source file, if any. If one exists, the flags for that file # should be good enough. If IsHeaderFile (filename): basename = os.path.splitext (filename) [0] for extension in SOURCE_EXTENSIONS: replacement_file = basename + extension if os.path.exists (replacement_file): compilation_info = database.GetCompilationInfoForFile (replacement_file) if compilation_info.compiler_flags_: return compilation_info return None return database.GetCompilationInfoForFile (filename) # This is the entry point This function is called by ycmd to produce flags for# a file.def FlagsForFile (filename, * * kwargs): if database: # Bear in mind that compilation_info.compiler_flags_ does NOT return a # python list, but a "list-like" StringVec object compilation_info = GetCompilationInfoForFile (filename) if not compilation_info: return None final_flags = MakeRelativePathsInFlagsAbsolute (compilation_info.compiler_flags_ Compilation_info.compiler_working_dir_) else: relative_to = DirectoryOfThisScript () final_flags = MakeRelativePathsInFlagsAbsolute (flags, relative_to) return {'flags': final_flags} root@Linux:~#

Automatic completion effect drawing

Error compiling clang

The relationship between ycm and vim

The above is all the contents of the article "how to install the vim YouCompleteMe auto-completion plug-in in ubuntu14.04". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report