处理"*.py"的BufRead自动命令时检测到错误

be-*_*dee 12 python vim

我的vim配置有问题...

打开python(.py)文件时会发生此错误:

Error detected while processing BufRead Auto commands for "*.py":
E20: Mark not set
Run Code Online (Sandbox Code Playgroud)

打开例如html(.html)或ruby(.rb)文件时,不会发生错误.

这是我的vim配置.插件全部安装完毕.

""" VUNDLE """
set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

" plugins
Plugin 'valloric/youcompleteme'
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'shawncplus/phpcomplete.vim'
Plugin 'quramy/tsuquyomi'
"Plugin 'Shougo/vimproc.vim'
Plugin 'leafgarland/typescript-vim'

call vundle#end()
filetype plugin indent on



""" CONFIG """
set history=200 "command history

set so=7 "add 7 lines when moving up/down

set hlsearch "highlight search results
set showmatch "highlight matching brackets

set ruler
set relativenumber

syntax enable
set encoding=utf8
set ffs=unix,dos,mac "unix as standard file type

set expandtab
set smarttab
set shiftwidth=4
set tabstop=4

set ai "Auto indent
set si "Smart indent
set nowrap "Wrap lines

set laststatus=2

" whitespace
set list
set listchars=tab:>-,trail:~,extends:>,precedes:<

set nobackup
set nowb
set noswapfile

" NERDTree
map <C-n> :NERDTreeToggle<CR>
"autocmd vimenter * NERDTree

" NERDTreeTabs
let NERDTreeShowHidden=1
let g:nerdtree_tabs_open_on_console_startup=1
map <Leader>n <plug>NERDTreeTabsToggle<CR>

au FileType php setl ofu=phpcomplete#CompletePHP
au FileType ruby,eruby setl ofu=rubycomplete#Complete
au FileType html,xhtml setl ofu=htmlcomplete#CompleteTags
au FileType css setl ofu=csscomplete#CompleteCSS
au FileType python setl ofu=pythoncomplete#Complete

au BufNewFile,BufRead *.py, *.php, *.rb, *.html, *.js, *.ts, *.md
    \ set tabstop=4 |
    \ set softtabstop=4 |
    \ set shiftwidth=4 |
    \ set textwidth=79 |
    \ set expandtab |
    \ set autoindent |
    \ set fileformat=unix


au BufNewFile,BufRead *.css, *.scss, *.json
    \ set tabstop=2 |
    \ set softtabstop=2 |
    \ set shiftwidth=2 |
    \ set textwidth=79 |
    \ set expandtab |
    \ set autoindent |
    \ set fileformat=unix

let g:ycm_python_binary_path = 'python'

if !exists("g:ycm_semantic_triggers")
  let g:ycm_semantic_triggers = {}
endif

" TypeScript plugin tsuquyomi
let g:ycm_semantic_triggers['typescript'] = ['.']
let g:tsuquyomi_import_curly_spacing = 0
let g:tsuquyomi_single_quote_import = 1
map <C-i> :TsuImport<CR>

hi Pmenu ctermbg=green
Run Code Online (Sandbox Code Playgroud)

我确实用不同的方式改变了"BufNewFile"这一行(1个set命令,多个set命令,带管道,没有管道,带有反斜杠,没有反斜杠等),但没有任何帮助.

有谁知道究竟是什么问题?

Ing*_*kat 26

这是很难发现(我不得不看两次),但问题是图案之间的空间:autocmd定义:

语法是

:au[tocmd] [group] {event} {pat} [nested] {cmd}
Run Code Online (Sandbox Code Playgroud)

:help {pat} 表明各个模式之间不能有空格.

:au BufNewFile,BufRead *.py, *.php, *.rb, *.html, *.js, *.ts, *.md echomsg 'test'

:au BufRead *.py
--- Auto-Commands ---
filetypedetect  BufRead
    *.py      setf python
BufRead
    *.py      *.php, *.rb, *.html, *.js, *.ts, *.md echomsg 'test'
Run Code Online (Sandbox Code Playgroud)

如您所见,Vim只识别第一个模式,并将所有后续命令作为(Ex)命令!

:*命令执行寄存器的内容(可能是垃圾),这会导致E20您看到的错误(可能是因为'寄存器中有字符).

固定

丢掉空白.正如我已经评论过的那样,您也可以跳过重复:set每个选项的命令.

:au BufNewFile,BufRead *.py,*.php,*.rb,*.html,*.js,*.ts,*.md ...
Run Code Online (Sandbox Code Playgroud)