update vim ocnf

This commit is contained in:
light jiang 2018-12-17 18:09:45 +08:00
parent 9271391f34
commit 051d1db55d
2 changed files with 237 additions and 111 deletions

View File

@ -1,5 +1,7 @@
" set the runtime path to include Vundle and initialize " set the runtime path to include Vundle and initialize
set rtp+=~/.fzf/ set rtp+=~/.fzf/
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin() call vundle#begin()
@ -66,8 +68,8 @@ Plugin 'https://github.com/tpope/vim-fugitive.git'
Plugin 'airblade/vim-gitgutter' Plugin 'airblade/vim-gitgutter'
set updatetime=100 set updatetime=100
Plugin 'https://github.com/plytophogy/vim-virtualenv.git' "Plugin 'https://github.com/plytophogy/vim-virtualenv.git'
let g:virtualenv_directory = '~/.virtualenv' "let g:virtualenv_directory = '~/.virtualenv'
Plugin 'godlygeek/tabular' Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown' Plugin 'plasticboy/vim-markdown'
@ -78,18 +80,16 @@ Plugin 'Valloric/YouCompleteMe'
set runtimepath+=~/.vim/bundle/YouCompleteMe set runtimepath+=~/.vim/bundle/YouCompleteMe
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口" autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口"
let g:ycm_collect_identifiers_from_tags_files = 1 " 开启 YCM基于标签引擎 let g:ycm_collect_identifiers_from_tags_files = 1 " 开启 YCM基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释与字符串中的内容也用于补全
"let g:syntastic_ignore_files=[".*\.py$"] "let g:syntastic_ignore_files=[".*\.py$"]
let g:ycm_seed_identifiers_with_syntax = 1 " 语法关键字补全 let g:ycm_seed_identifiers_with_syntax = 1 " 语法关键字补全
let g:ycm_complete_in_comments = 1
let g:ycm_confirm_extra_conf = 0 " 关闭加载.ycm_extra_conf.py提示 let g:ycm_confirm_extra_conf = 0 " 关闭加载.ycm_extra_conf.py提示
let g:ycm_key_list_select_completion = ['<c-n>', '<Down>'] " 映射按键,没有这个会拦截掉tab, 导致其他插件的tab不能用. let g:ycm_key_list_select_completion = ['<c-n>', '<Down>'] " 映射按键,没有这个会拦截掉tab, 导致其他插件的tab不能用.
let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>'] let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>']
let g:ycm_complete_in_comments = 1 " 在注释输入中也能补全 let g:ycm_complete_in_comments = 1 " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1 " 在字符串输入中也能补全 let g:ycm_complete_in_strings = 1 " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全 let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全
"let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py' let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py' "let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
let g:ycm_show_diagnostics_ui = 0 " 禁用语法检查 let g:ycm_show_diagnostics_ui = 0 " 禁用语法检查
"inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" " 回车即选中当前项 "inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" " 回车即选中当前项
nnoremap <c-d> :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳转到定义处 nnoremap <c-d> :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳转到定义处
@ -109,6 +109,12 @@ let g:closetag_filenames = '*.html,*.xhtml,*.phtml,*.launch'
Plugin 'jiangmiao/auto-pairs' Plugin 'jiangmiao/auto-pairs'
Plugin 'Chiel92/vim-autoformat'
noremap <F6> :Autoformat<CR>:w<CR>
let g:autoformat_verbosemode=1
Plugin 'vim-airline/vim-airline' Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline-themes' Plugin 'vim-airline-themes'
let g:airline_theme='bubblegum' let g:airline_theme='bubblegum'
@ -221,7 +227,7 @@ func! CompileRunGcc()
exec '!g++ % -o %<' exec '!g++ % -o %<'
exec '!time ./%<' exec '!time ./%<'
elseif &filetype == 'cpp' elseif &filetype == 'cpp'
exec '!g++ % -o %<' exec '!g++ % -o %< -lboost_system'
exec '!time ./%<' exec '!time ./%<'
elseif &filetype == 'python' elseif &filetype == 'python'
exec '!time python %' exec '!time python %'
@ -345,7 +351,7 @@ set scrolloff=3
" 为C程序提供自动缩进 " 为C程序提供自动缩进
set smartindent set smartindent
" 高亮显示普通txt文件需要txt.vim脚本 " 高亮显示普通txt文件需要txt.vim脚本
au BufRead,BufNewFile * setfiletype txt au BufRead,BufNewFile * setfiletype txt
filetype plugin indent on filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全 "打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu set completeopt=longest,menu

View File

@ -1,102 +1,222 @@
#!/usr/bin/env python # This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
from distutils.sysconfig import get_python_inc
import platform
import os import os
import subprocess
import ycm_core import ycm_core
project_path = os.path.abspath(os.path.dirname(__file__))
DIR_OF_THIS_SCRIPT = "/home/light/.vim/bundle/YouCompleteMe"
DIR_OF_THIRD_PARTY = os.path.join(DIR_OF_THIS_SCRIPT, 'third_party')
SOURCE_EXTENSIONS = ['.cpp', '.cxx', '.cc', '.c', '.m', '.mm']
# 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 = [ flags = [
'-Wall', '-Wall',
'-Wextra', '-Wextra',
'-Werror', '-Werror',
'-fexceptions', '-Wno-long-long',
'-DNDEBUG', '-Wno-variadic-macros',
'-std=c++11', '-fexceptions',
'-x', '-DNDEBUG',
'c++', # You 100% do NOT need -DUSE_CLANG_COMPLETER and/or -DYCM_EXPORT in your flags;
'-isystem', # only the YCM source code needs it.
'/usr/include', '-DUSE_CLANG_COMPLETER',
'-isystem', '-DYCM_EXPORT=',
'/usr/local/include', # THIS IS IMPORTANT! Without the '-x' flag, Clang won't know which language to
'-isystem', # use when compiling headers. So it will guess. Badly. So C++ headers will be
'/opt/ros/' + os.getenv('ROS_DISTRO') + '/include', # compiled as C headers. You don't want that so ALWAYS specify the '-x' flag.
'-isystem', # For a C project, you would set this to 'c' instead of 'c++'.
'~/catkin_ws/devel/include', '-x',
'c++',
'-isystem',
'cpp/pybind11',
'-isystem',
'cpp/BoostParts',
'-isystem',
get_python_inc(),
'-isystem',
'cpp/llvm/include',
'-isystem',
'cpp/llvm/tools/clang/include',
'-I',
'cpp/ycm',
'-I',
'cpp/ycm/ClangCompleter',
'-isystem',
'cpp/ycm/tests/gmock/gtest',
'-isystem',
'cpp/ycm/tests/gmock/gtest/include',
'-isystem',
'cpp/ycm/tests/gmock',
'-isystem',
'cpp/ycm/tests/gmock/include',
'-isystem',
'cpp/ycm/benchmarks/benchmark/include',
'-isystem',
project_path + '/includes',
'-I',
project_path + '/src',
] ]
# Clang automatically sets the '-std=' flag to 'c++14' for MSVC 2015 or later,
# which is required for compiling the standard library, and to 'c++11' for older
# versions.
if platform.system() != 'Windows':
flags.append('-std=c++11')
# 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 = '' compilation_database_folder = ''
if os.path.exists( compilation_database_folder ): if os.path.exists(compilation_database_folder):
database = ycm_core.CompilationDatabase( compilation_database_folder ) database = ycm_core.CompilationDatabase(compilation_database_folder)
else: else:
database = None database = None
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c' ]
def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): def IsHeaderFile(filename):
if not working_directory: extension = os.path.splitext(filename)[1]
return list( flags ) return extension in ['.h', '.hxx', '.hpp', '.hh']
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 ): def FindCorrespondingSourceFile(filename):
extension = os.path.splitext( filename )[ 1 ] if IsHeaderFile(filename):
return extension in [ '.h', '.hxx', '.hpp', '.hh' ] basename = os.path.splitext(filename)[0]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists(replacement_file):
return replacement_file
return filename
def GetCompilationInfoForFile( filename ): def PathToPythonUsedDuringBuild():
if IsHeaderFile( filename ): try:
basename = os.path.splitext( filename )[ 0 ] filepath = os.path.join(
for extension in SOURCE_EXTENSIONS: DIR_OF_THIS_SCRIPT, 'PYTHON_USED_DURING_BUILDING')
replacement_file = basename + extension with open(filepath) as f:
if os.path.exists( replacement_file ): return f.read().strip()
compilation_info = database.GetCompilationInfoForFile( # We need to check for IOError for Python 2 and OSError for Python 3.
replacement_file ) except (IOError, OSError):
if compilation_info.compiler_flags_: return None
return compilation_info
return None
return database.GetCompilationInfoForFile( filename )
def FlagsForFile( filename, **kwargs ): def Settings(**kwargs):
if database: language = kwargs['language']
compilation_info = GetCompilationInfoForFile( filename )
if not compilation_info:
return None
final_flags = MakeRelativePathsInFlagsAbsolute( if language == 'cfamily':
compilation_info.compiler_flags_, # If the file is a header, try to find the corresponding source file and
compilation_info.compiler_working_dir_ ) # retrieve its flags from the compilation database if using one. This is
else: # necessary since compilation databases don't have entries for header files.
relative_to = DirectoryOfThisScript() # In addition, use this source file as the translation unit. This makes it
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) # possible to jump from a declaration in the header file to its definition
# in the corresponding source file.
filename = FindCorrespondingSourceFile(kwargs['filename'])
return { if not database:
'flags': final_flags, return {
'do_cache': True 'flags': flags,
} 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT,
'override_filename': filename
}
compilation_info = database.GetCompilationInfoForFile(filename)
if not compilation_info.compiler_flags_:
return {}
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object.
final_flags = list(compilation_info.compiler_flags_)
# 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
return {
'flags': final_flags,
'include_paths_relative_to_dir': compilation_info.compiler_working_dir_,
'override_filename': filename
}
if language == 'python':
return {
'interpreter_path': PathToPythonUsedDuringBuild()
}
return {}
def GetStandardLibraryIndexInSysPath(sys_path):
for index, path in enumerate(sys_path):
if os.path.isfile(os.path.join(path, 'os.py')):
return index
raise RuntimeError('Could not find standard library path in Python path.')
def PythonSysPath(**kwargs):
sys_path = kwargs['sys_path']
sys_path.insert(0, DIR_OF_THIS_SCRIPT)
for folder in os.listdir(DIR_OF_THIRD_PARTY):
if folder == 'python-future':
folder = os.path.join(folder, 'src')
sys_path.insert(GetStandardLibraryIndexInSysPath(sys_path) + 1,
os.path.realpath(os.path.join(DIR_OF_THIRD_PARTY,
folder)))
continue
if folder == 'cregex':
interpreter_path = kwargs['interpreter_path']
major_version = subprocess.check_output([
interpreter_path, '-c', 'import sys; print( sys.version_info[ 0 ] )']
).rstrip().decode('utf8')
folder = os.path.join(folder, 'regex_{}'.format(major_version))
sys_path.insert(0, os.path.realpath(os.path.join(DIR_OF_THIRD_PARTY,
folder)))
return sys_path