- 浏览: 44682 次
- 性别:
- 来自: 广州
文章分类
参考: http://valloric.github.io/YouCompleteMe/
http://blog.marchtea.com/archives/161
一, 安装准备:
1, Vim 版本 7.3.584+ 编译时 添加 +python 标识
// 安装python-dev2.7 mac默认已安装
命令行 vim —version 查看 vim 版本 或进入vim 后输入 :version
查看是否支持 python :echo has('python') 输出1表示支持 输入0则否
Mac通过 brew install vim 安装最新的7.4 版本的vim : /usr/local/Cellar/vim/7.4.335/bin
在~/.bash_profile 添加: export PATH=/usr/local/Cellar/vim/7.4.335/bin:$PATH
2, 安装cmake
查看 which cmake 是否 已安装 ,http://www.cmake.org下载 cmake-2.6.4.tar.gz
tar -xzvf cmake-2.6.4.tar.gz
cd cmake-2.6.4
./bootstrap
make
make install
3, 下载 clang binary版本 3.2以上版本 官网 http://clang.llvm.org
将clang+llvm-3.3-x86_64-apple-darwin12.tar 解压到 ~/ycm_temp/llvm_root_dir目录
// ~/ycm_temp/llvm_root_dir (with bin, lib, include etc. right inside that folder)
4,安装vundle插件 利用 vundle 安装 YCM插件
$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
配置~/.vimrc 参考: http://valloric.github.io/YouCompleteMe/
二,安装
1, 执行 vim +PluginInstall +qall 让vundle把YCM插件下载到本地,网速慢等待比较久
YCM下载到~/.vim/bundle之后,开始编译 YCM
--> cd ~ && mkdir ycm_build
--> cd ycm_build
--> cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/ycm_temp/llvm_root_dir . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp // 注意 llvm_root_dir . ~/
--> make ycm_support_libs
--> make
// it will also place the libclang.[so|dylib] in the YouCompleteMe/python folder for you if you compiled with clang support (it needs to be there for YCM to work).
如果没提示报错,则安装编译成功
2,配置
YCM looks for a .ycm_extra_conf.py file in the directory of the opened file or in any directory above it in the hierarchy (recursively);
Don't just copy/paste that file somewhere and expect things to magically work;
your project needs different flags.
Hint: just replace the strings in the flags variable with compilation flags necessary for your project.
:YcmDiags // to see if any errors or warnings were detected in your file.
:YcmForceCompileAndDiagnostics // recompile
:YcmDebugInfo
:messages
" let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_key_invoke_completion = '<C-/>' " 或 '<M-/>' 默认是CTRL + space
导航定义和声明
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
YCM提供的跳跃功能采用了vim的jumplist,往前跳和往后跳的快捷键为Ctrl+O以及Ctrl+I.
问题: 找不到STL相关定义:
解决方法:
call echo | clang -v -E -x c++ - and look at the paths under the #include <...> search starts here: heading.
You should take those paths, prepend -isystem to each individual path and append them all to the list of flags in your .ycm_extra_conf.py file.
将flags 一些无用的 -I -isystem 需要清理掉.
string str; 需要 std::string str;才会补全。
.ycm_extra_conf.py 文件一览:
flags = [ ] 中的路径根据具体情况配置
~/ 根路径放置一个 fallback ycm_extra_conf.py
然后在每个项目路径放置一个各自的ycm_extra_conf.py
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
import os
import 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',
#'-Wc++98-compat',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-stdlib=libc++',
#'-DNDEBUG',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
#'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++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 'c++'.
'-x',
'c++',
'-I',
'.',
'-isystem',
'/System/Library/Frameworks/Python.framework/Headers',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks',
]
# 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
#
# You can get CMake to generate this file for you by adding:
# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''
if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
SOURCE_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', '-I', '-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_flags
def 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 )
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_ )
# NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
# ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
#try:
# final_flags.remove( '-stdlib=libc++' )
#except ValueError:
# pass
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
return {
'flags': final_flags,
'do_cache': True
}
http://blog.marchtea.com/archives/161
一, 安装准备:
1, Vim 版本 7.3.584+ 编译时 添加 +python 标识
// 安装python-dev2.7 mac默认已安装
命令行 vim —version 查看 vim 版本 或进入vim 后输入 :version
查看是否支持 python :echo has('python') 输出1表示支持 输入0则否
Mac通过 brew install vim 安装最新的7.4 版本的vim : /usr/local/Cellar/vim/7.4.335/bin
在~/.bash_profile 添加: export PATH=/usr/local/Cellar/vim/7.4.335/bin:$PATH
2, 安装cmake
查看 which cmake 是否 已安装 ,http://www.cmake.org下载 cmake-2.6.4.tar.gz
tar -xzvf cmake-2.6.4.tar.gz
cd cmake-2.6.4
./bootstrap
make
make install
3, 下载 clang binary版本 3.2以上版本 官网 http://clang.llvm.org
将clang+llvm-3.3-x86_64-apple-darwin12.tar 解压到 ~/ycm_temp/llvm_root_dir目录
// ~/ycm_temp/llvm_root_dir (with bin, lib, include etc. right inside that folder)
4,安装vundle插件 利用 vundle 安装 YCM插件
$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
配置~/.vimrc 参考: http://valloric.github.io/YouCompleteMe/
二,安装
1, 执行 vim +PluginInstall +qall 让vundle把YCM插件下载到本地,网速慢等待比较久
YCM下载到~/.vim/bundle之后,开始编译 YCM
--> cd ~ && mkdir ycm_build
--> cd ycm_build
--> cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/ycm_temp/llvm_root_dir . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp // 注意 llvm_root_dir . ~/
--> make ycm_support_libs
--> make
// it will also place the libclang.[so|dylib] in the YouCompleteMe/python folder for you if you compiled with clang support (it needs to be there for YCM to work).
如果没提示报错,则安装编译成功
2,配置
YCM looks for a .ycm_extra_conf.py file in the directory of the opened file or in any directory above it in the hierarchy (recursively);
Don't just copy/paste that file somewhere and expect things to magically work;
your project needs different flags.
Hint: just replace the strings in the flags variable with compilation flags necessary for your project.
:YcmDiags // to see if any errors or warnings were detected in your file.
:YcmForceCompileAndDiagnostics // recompile
:YcmDebugInfo
:messages
" let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_key_invoke_completion = '<C-/>' " 或 '<M-/>' 默认是CTRL + space
导航定义和声明
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
YCM提供的跳跃功能采用了vim的jumplist,往前跳和往后跳的快捷键为Ctrl+O以及Ctrl+I.
问题: 找不到STL相关定义:
解决方法:
call echo | clang -v -E -x c++ - and look at the paths under the #include <...> search starts here: heading.
You should take those paths, prepend -isystem to each individual path and append them all to the list of flags in your .ycm_extra_conf.py file.
将flags 一些无用的 -I -isystem 需要清理掉.
string str; 需要 std::string str;才会补全。
.ycm_extra_conf.py 文件一览:
flags = [ ] 中的路径根据具体情况配置
~/ 根路径放置一个 fallback ycm_extra_conf.py
然后在每个项目路径放置一个各自的ycm_extra_conf.py
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
import os
import 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',
#'-Wc++98-compat',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-stdlib=libc++',
#'-DNDEBUG',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
#'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++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 'c++'.
'-x',
'c++',
'-I',
'.',
'-isystem',
'/System/Library/Frameworks/Python.framework/Headers',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks',
]
# 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
#
# You can get CMake to generate this file for you by adding:
# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''
if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
SOURCE_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', '-I', '-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_flags
def 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 )
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_ )
# NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
# ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
#try:
# final_flags.remove( '-stdlib=libc++' )
#except ValueError:
# pass
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
return {
'flags': final_flags,
'do_cache': True
}
发表评论
-
vim搜索插件ctrlsf
2014-12-02 10:24 6156地址: https://github.com/dyng/ctr ... -
vim快捷键
2014-08-29 19:55 340查找vim中某个键映射的定义: 打开vim输入下面的命令 例 ... -
vim编码
2014-09-01 20:08 331~/.vimrc 配置 set encoding=u ... -
vim设置color
2014-08-22 17:01 562经过以上配置还是没有语法高亮,那么这时候也不要灰心,需要从下面 ... -
svn配置
2014-08-15 16:44 336系统debian: 安装: apt-get install ... -
vim主题
2014-08-11 14:20 4291,freya.vim http://www.vim.org/ ... -
vim插件管理工具vundle
2014-08-10 14:20 12221,安装: $ git clone https://githu ... -
vim常用插件
2014-08-08 11:24 556参考:http://blog.csdn.net/y ... -
vitualbox安装dabian
2014-08-07 19:37 524安装: Oracle VM VirtualBox 下载: de ... -
vim基础操作
2014-08-07 19:20 307参考:http://www.cnblogs.com/sunor ... -
centos用户管理
2014-09-01 20:08 554在linux下用户是根据角 ... -
win7远程登录Centos系统
2014-07-22 12:01 394转自:http://jingyan.baidu.com/art ... -
win7 设置
2014-07-22 11:56 283vista或windows 7的系统默认安装是没有安装这个组件 ... -
ssh修改默认端口
2014-07-22 11:54 599Secure Shell 转自: http://os.51 ... -
centos安装vmwaretool
2014-07-21 17:02 305將VMWare的光碟設定成 yourinstallpath\l ... -
常用脚本
2014-05-04 15:18 295telnet localhost 7000 查看磁盘还剩多少 ... -
文件系统
2012-08-19 13:16 546所谓“文件”是指一组 ...
相关推荐
Ubuntu 14 以上系统快速安装YouCompleteMe实现vim的智能提示Ubuntu 14 以上系统快速安装YouCompleteMe实现vim的智能提示
youcompleteme file插件下载之后的完整包
Atom-atom-youcompleteme.zip,YouCompleteMe for Atom编辑器Atom YouCompleteMe包,atom是一个用web技术构建的开源文本编辑器。
Vim自动补全插件----YouCompleteMe安装与配置
在ubuntu18.04中安装插件管理工具以及nedrtree和YouCompleteMe插件
ycmd包,(linux下使用)是 YouCompleteMe插件的必须组件,但是git上很难下载,经常下载出错,我废了好大劲儿终于下载成功
自用的YouCompleteMe安装包,21年年初的版本,已在windows、Mac、ubuntu18.04、ubuntu20.04.01上验证可用。 已下载ubuntu上安装C++语法提示所需要的附加软件包,安装过程无需再联网下载,安装方便快捷。 安装过程...
在这里分享我的有关vim的所有配置与插件(含自动补全插件YouCompleteMe),图省事、不想边安装边的朋友可以直接尝试下,不保证不会出现任何问题。注意:该配置文件解压后,请在root模式下复制至root根目录下,如果...
安装简易, 功能强大,支持ubuntu下YouCompleteMe安装, 完整的代码提示功能!!!
最新.2020.10.31最新youcompleteme补全.你只需要下载这一个. 然后安装即可.在网速不够,或下午速度不够时,可以直接下载它.
atom-youcompleteme:适用于Atom编辑器的YouCompleteMe
ycm 包含子模块打包文件,可以直接安装。资源地址https://github.com/ycm-core/YouCompleteMe.git,使用git submodule update --init --recursive ,下载完成了子模块,大小是196M,压缩后149M
YouCompleteMe被称为Vim最难配置的插件,当初配置好YouCompleteMe也是费了九牛二虎之力,印象中是花了整整一个晚上。回报也是显然的,支持定义跳转,变量跳转,超快的自动补全。下面进入正题。 首先是自动补全的机制...
YouCompleteMe 完整安装包 -------------YCM-------------------- ~~~~~~~~~~下载~~~~~~~~~~~~~
Windows下编译通过的YCM: python2.7, VS2015, 可直接放在vundle下使用。
用于离线安装ycm,不需要花费很多时间从GitHub上慢慢下。使用python3进行安装的,需要cmake等一些必要组件,详细安装方法在我博客上。