如何处理我的vim局部变量(omnifunc,...),它没有设置为我在vimrc中写的

时间:2017-11-07 03:17:37

标签: vim autocomplete

我在VIM中使用omnicomplete,我的vimrc如下所示。

...剪断

" Autocompletion
set completeopt=longest,noselect,menuone
set omnifunc=syntaxcomplete#Complete
autocmd FileType py set omnifunc=python3complete#Complete

但是,当我重启vim时。 omn​​ifunc不能像我设置的那样工作,即使值与我的vimrc设置不同

我认为我的恢复选项有问题。但是,阻止以下设置。

" Save and load former states
"autocmd BufWinLeave ?* mkview
"autocmd BufWinEnter ?* silent loadview

它仍然不起作用...... 我该如何解决? 感谢您的所有帮助。

2017.11.08编辑>这是我完整的.vimrc文件

syntax on 
set nocp        " no compatibility with VI
set nu          " line number
set cursorline  " highlight current cursorline
set ruler       " display cursor position information at status line
set ic          " case insensitive search
set smartcase   " don't use ic when there is Capital letter
set hlsearch    " hilight search
set incsearch   " show search matches as type
set mouse=a     " enalbe cursor move with mouse
set ts=4        " size of \t character (tab stop)
set sw=4        " tab size, when use <<, >>
set sts=4       " how many spaces, when type tab (soft tab stop)
set ls=2        " last window's status line option
set expandtab smarttab
set autowrite   " Automatically :write before running commands
set autoread    " Auto read when a file is changed on disk
set autoindent
set smartindent
set cindent
set vb noeb     " visual bell instead of beep
set tm=500 ttm=0    " to leave insert mode without delay
set encoding=utf8

" Autocompletion
set completeopt=longest,noselect,menuone
set omnifunc=syntaxcomplete#Complete
autocmd FileType py set omnifunc=python3complete#Complete

" Cursor shape
let &t_SI = "\e[5 q"    " Start Insert mode
let &t_EI = "\e[0 q"    " End Insert mode

" Key mapping
nnoremap <F2>    :!ctags -R -I --languages=C,C++ --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
nnoremap <F3>    :NERDTreeToggle<CR>
nnoremap <F4>    :TlistToggle<CR>
nnoremap <F5>    <C-w>=
nnoremap Y  y$
nnoremap n  nzz
nnoremap N  Nzz
nnoremap *  *zz
nnoremap #  #zz
inoremap <C-h>  <Left>
inoremap <C-j>  <Down>
inoremap <C-k>  <Up>
inoremap <C-l>  <Right>
inoremap <C-b>  <C-Left>
inoremap <C-f>  <C-Right>
inoremap <C-a>  <Esc>I
inoremap <C-e>  <End>
inoremap <C-@>  <C-x><C-o>
autocmd FileType c,h,cpp,hpp inoremap {<ENTER>      {}<Left><ENTER><ENTER><UP><TAB>

" Save and load former states
autocmd BufWinLeave ?* mkview
autocmd BufWinEnter ?* silent loadview

" C/C++ header
function! s:header()
    let name = "__".toupper(substitute(expand("%:t"), "\\.", "_", "g"))."__"
    exe "norm! i#ifndef ". name "\n#define ". name "\n\n\n\n#endif\t//". name "\ekk"
endfunction
autocmd BufNewFile *.{h,hpp} call <SID>header()

" Python header
function! s:py_init()
    exe "norm! i\n\n\ndef main():\npass\n\n\eIif __name__ == \"__main__\":\n\tmain()\n\egg"
endfunction
autocmd BufNewFile *.py call <SID>py_init()


" Plugin settings using Vundle
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tpope/vim-fugitive'
Plugin 'scrooloose/nerdtree'
Plugin 'taglist-plus'
Plugin 'nanotech/jellybeans.vim'

call vundle#end()
filetype plugin indent on

" airline settings
set laststatus=2
let g:airline#extensions#tabline#enabled=1    " turn on buffer list
let g:airline_theme='murmur'
let g:airline_powerline_fonts=1
let g:airline#extensions#branch#enabled=1

" NERDTree settings 
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let g:NERDTreeDirArrowExpandable='+'
let g:NERDTreeDirArrowCollapsible='~'

" taglist settings
let Tlist_Use_Right_Window=1

" Color settings with bundle theme (type help highlight in order to see color list)
if has("gui_running")
    colo industry   " industry, torte, koehler
else
    colo slate      " slate, koehler, ron, elflord, pablo
endif
colo jellybeans
highlight linenr        ctermfg=brown ctermbg=NONE
highlight cursorlinenr  ctermfg=green ctermbg=NONE
highlight cursorline    cterm=underline

1 个答案:

答案 0 :(得分:4)

您可以通过

找到最后设置选项的位置
:verbose set omnifunc?

您的问题似乎是由:autocmd中的错误文件类型引起的。虽然Python文件通常具有*.py扩展名,但Vim中的文件类型名为python。所以,这应该有效:

autocmd FileType python set omnifunc=python3complete#Complete

其他批评

  • 我建议将设置和映射放入~/.vim/after/ftplugin/python.vim,而不是定义大量:autocmd FileType python;它更清洁,更好地扩展;但要求您拥有:filetype plugin on
  • 通过使用:set'omnifunc'的值将由从Python打开的其他缓冲区继承(例如,通过:new)。通常,这不是你想要的。请改用:setlocal omnifunc=...