Skip to main content
 首页 » 编程设计

python之YouCompleteMe:键入时触发自动完成(不使用 TAB 键插入的建议)

2024年10月24日8haluo1

当我输入时,YouCompleteMe 会自动插入建议,而无需我按 TAB 键。当我输入 self 时,这会导致像 selflf 这样的东西,或者我不能再写 file 了,因为 YouCompleteMe 会自动插入一个来 self 的文件 fill_jacobian 的函数。从 YouCompleteMe 自述文件中,我认为该插件不应该那样运行。难道我做错了什么?我的 ~/.vimrc 如下所示:

set nocompatible              " be iMproved, required 
filetype off                  " required 
 
" set the runtime path to include Vundle and initialize 
set rtp+=~/.vim/bundle/Vundle.vim 
call vundle#begin() 
" alternatively, pass a path where Vundle should install plugins 
"call vundle#begin('~/some/path/here') 
 
" let Vundle manage Vundle, required 
Plugin 'gmarik/Vundle.vim' 
 
" The following are examples of different formats supported. 
" Keep Plugin commands between vundle#begin/end. 
" plugin on GitHub repo 
Plugin 'tpope/vim-fugitive' 
" plugin from http://vim-scripts.org/vim/scripts.html 
Plugin 'L9' 
" Git plugin not hosted on GitHub 
Plugin 'git://git.wincent.com/command-t.git' 
" git repos on your local machine (i.e. when working on your own plugin) 
Plugin 'file:///home/gmarik/path/to/plugin' 
" The sparkup vim script is in a subdirectory of this repo called vim. 
" Pass the path to set the runtimepath properly. 
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} 
" Avoid a name conflict with L9 
Plugin 'Valloric/YouCompleteMe' 
" Plugin 'scrooloose/syntastic' 
Plugin 'pangloss/vim-javascript' 
Plugin 'user/L9', {'name': 'newL9'} 
 
 
" All of your Plugins must be added before the following line 
call vundle#end()            " required 
filetype plugin indent on    " required 
" To ignore plugin indent changes, instead use: 
"filetype plugin on 
" 
" Brief help 
" :PluginList       - lists configured plugins 
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate 
" :PluginSearch foo - searches for foo; append `!` to refresh local cache 
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal 
" 
" see :h vundle for more details or wiki for FAQ 
" Put your non-Plugin stuff after this line 
 
set nocompatible    " use vim defaults 
set ls=2            " allways show status line 
set tabstop=4       " numbers of spaces of tab character 
set shiftwidth=4    " numbers of spaces to (auto)indent 
set scrolloff=3     " keep 3 lines when scrolling 
"set showcmd         " display incomplete commands 
set hlsearch        " highlight searches 
set incsearch       " do incremental searching 
set ruler           " show the cursor position all the time 
set visualbell t_vb=    " turn off error beep/flash 
set novisualbell    " turn off visual bell 
"set nobackup        " do not keep a backup file 
set number          " show line numbers 
set ignorecase      " ignore case when searching  
"set noignorecase   " don't ignore case 
set title           " show title in console title bar 
set ttyfast         " smoother changes 
"set ttyscroll=0        " turn off scrolling, didn't work well with PuTTY 
set modeline        " last lines in document sets vim mode 
set modelines=3     " number lines checked for modelines 
"set shortmess=atI   " Abbreviate messages 
set nostartofline   " don't jump to first character when paging 
set whichwrap=b,s,h,l,<,>,[,]   " move freely between files 
"set viminfo='20,<50,s10,h 
 
set autoindent     " always set autoindenting on 
set smartindent        " smart indent 
"set cindent            " cindent 
"set noautoindent 
"set nosmartindent 
"set nocindent 
set cinkeys=0{,0},!^F,o,O,e " default is: 0{,0},0),:,0#,!^F,o,O,e 
 
"set autowrite      " auto saves changes when quitting and swiching buffer 
set expandtab      " tabs are converted to spaces, use only when required 
"set sm             " show matching braces, somewhat annoying... 
"set nowrap         " don't wrap lines 
 
 
syntax on           " syntax highlighing 
if has("gui_running") 
    " See ~/.gvimrc 
    set guifont=Monospace\ 10  " use this font  
    set lines=50       " height = 50 lines 
    set columns=100        " width = 100 columns 
    set background=light   " adapt colors for background 
    set selectmode=mouse,key,cmd 
    set keymodel= 
else 
    "colorscheme elflord    " use this color scheme 
    set background=light       " adapt colors for background 
endif 
 
if has("autocmd") 
    " Restore cursor position 
    au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif 
 
    " Filetypes (au = autocmd) 
    au FileType helpfile set nonumber      " no line numbers when viewing help 
    au FileType helpfile nnoremap <buffer><cr> <c-]>   " Enter selects subject 
    au FileType helpfile nnoremap <buffer><bs> <c-T>   " Backspace to go back 
 
    " When using mutt, text width=72 
    au FileType mail,tex set textwidth=72 
    "au FileType cpp,c,java,sh,pl,php,phtml,asp  set autoindent 
    au FileType cpp,c,java,sh,pl,php,phtml,asp,xml,javascript  set smartindent 
    nnoremap <C-p> :set invpaste paste?<CR> 
    set pastetoggle=<C-p> 
    set showmode 
    "au FileType cpp,c,java,sh,pl,php,phtml,asp  set cindent 
    "au BufRead mutt*[0-9] set tw=72 
 
    " Automatically chmod +x Shell and Perl scripts 
    "au BufWritePost   *.sh             !chmod +x % 
    "au BufWritePost   *.pl             !chmod +x % 
 
    " File formats 
    au BufNewFile,BufRead  *.phtml  set syntax=php 
    au BufNewFile,BufRead  *.pls    set syntax=dosini 
    au BufNewFile,BufRead  modprobe.conf    set syntax=modconf 
 
    " Ctrl+X O 
    autocmd FileType python set omnifunc=pythoncomplete#Complete 
    autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS 
    autocmd FileType html set omnifunc=htmlcomplete#CompleteTags 
    autocmd FileType css set omnifunc=csscomplete#CompleteCSS 
    autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags 
    autocmd FileType php set omnifunc=phpcomplete#CompletePHP 
    autocmd FileType c set omnifunc=ccomplete#Complete 
    autocmd FileType make set noexpandtab shiftwidth=8 softtabstop=0 
    autocmd FileType php noremap <C-L> :!php -l %<CR> 
    autocmd Filetype html,xml,xsl source ~/.vim/closetag.vim 
endif 

请您参考如下方法:

显然 .vimrc 中的一些重新映射会干扰 YouCompleteMe。参见 https://github.com/Valloric/YouCompleteMe/issues/783