“*.py”文件的BufRead自动命令处理过程中检测到错误。

32

我对我的vim配置有问题...

当打开Python(.py)文件时出现以下错误:

Error detected while processing BufRead Auto commands for "*.py":
E20: Mark not set

当打开例如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

我曾以不同方式(1个set命令、多个set命令、带管道、不带管道、带反斜杠、不带反斜杠等)更改了带有"BufNewFile"的那一行,但没有任何帮助。

是否有人知道问题到底是什么?


你确定是你的.vimrc文件中的:au BufRead *.py引起的问题吗?当你将其注释掉时,问题是否消失了?我认为这是由某个(文件类型)插件引起的。请问:au BufRead *.py的输出是什么? - Ingo Karkat
1
哦,你可以在一个 :set 命令后放置所有选项:set ts=4 sts=4 sw=4 ... 这样,你可能就不需要换行了。 - Ingo Karkat
@IngoKarkat 如果我只是从带有 BufRead 的行中删除 *.py 扩展名,那么打开 Python 文件时就不会出现错误。 - user4923309
1个回答

52

很难注意到(我不得不看两次),但是问题在于:autocmd定义中的模式之间的空格:

语法如下:

:au[tocmd] [group] {event} {pat} [nested] {cmd}

: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'

正如您所看到的,Vim只识别第一个模式,并将所有后续内容视为(Ex)命令!

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

修复

去掉空格。正如我已经评论过的那样,您也可以跳过为每个选项重复执行 :set 命令。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接