python - unix vim 处理 BufRead 自动命令时检测到错误

标签 python vim

我是一个新的 vim 用户,按照本指南使 vim 自动缩进 python 代码并标记不必要的空格:https://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/#vim-extensions

我遇到的问题是当我在 .py 文件上启动 vim 时收到此错误:处理“*.py”的 BufRead 自动命令时检测到错误: E28: 没有这样的高亮组名:BadWhitespace

这个错误我注释掉下面几行:

" Flag unnecessary whitespace                                           
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/   <- this line   

" UTF8 Support                                                          
set encoding=utf-8                                                      
" Proper PEP8 Identation                                                
au BufNewFile,BufRead *.py                                              
    \ set tabstop=4                                                     
"    \ set softtabstop=4      <-- this line                                          
    \ set shiftwidth=4                                                  
    \ set textwidth=79                                                  
    \ set expandtab                                                     
    \ set autoindent                                                    
    \ set fileformat=unix         

如何解决这个错误?这是我完整的 .vimrc 文件:

set nocompatible              " required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=/home/frank/.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'

" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)
Plugin 'tmhedberg/SimpylFold'
Plugin 'vim-scripts/indentpython.vim'
Bundle 'Valloric/YouCompleteMe'
Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'kien/ctrlp.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
" ...

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

" Split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" Enable folding
set foldmethod=indent
set foldlevel=99
" Enable folding with the spacebar
nnoremap <space> za
" See docstrings for folded code
let g:SimpylFold_docstring_preview=1

" Flag unnecessary whitespace
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/      <-this line

" UTF8 Support
set encoding=utf-8
" Proper PEP8 Identation        <-this line
au BufNewFile,BufRead *.py
    \ set tabstop=4
"    \ set softtabstop=4 
    \ set shiftwidth=4
    \ set textwidth=79
    \ set expandtab
    \ set autoindent
    \ set fileformat=unix

" For Full stack development 'au' command
"au BufNewFile,BufRead *.js, *.html, *.css
"    \ set tabstop=2
"    \ set softtabstop=2
"    \ set shiftwidth=2

" YouCompleteMe plugin customization
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>

"python with virtualenv support
py << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
  project_base_dir = os.environ['VIRTUAL_ENV']
  activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
  execfile(activate_this, dict(__file__=activate_this))
EOF

" Makes python code pretty
let python_highlight_all=1
syntax on

" Adds a bit of logic to define which color scheme to use based upon VIM mode
if has('gui_running')
  set background=dark
  colorscheme solarized
else
  colorscheme zenburn
endif

" Press F5 to toggle between dark and light theme
call togglebg#map("<F5>")

" Hybrid line numbers
:set number relativenumber
:augroup numbertoggle
:  autocmd!
:  autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
:  autocmd BufLeave,FocusLost,InsertEnter   * set norelativenumber
:augroup END

set pastetoggle=<F10>

最佳答案

有一个更简单的解决方案。你看我遇到了同样的问题,在这个小技巧之后没有错误消息,一切都在正常工作。

诀窍是,BufNewFile、BufRead 应该用空格分隔。 所以这条线应该看起来像

au BufNewFile, BufRead *.py

而不是 au BufNewFile,BufRead *.py 最好的问候

关于python - unix vim 处理 BufRead 自动命令时检测到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48869590/

相关文章:

python - 来自 yahoo finance(或 google finance)的价格数据比每天一个点更精确

python - 记录所有 Django 弃用警告

vim - Vim 中的这些红色箭头是什么意思?

python - 在 Syntastic for Vim 中仅对 Python 文件启用 pylint

python - 如何在 Windows 上使用 subprocess.run 运行 bash 命令

python - 了解 Scapy 数据结构

python - 将python中的数组列表转换为grasshopper中的树

vim - 如何在 vim 中重新映射 <C> (控制)修饰键?

bash - 如何在 Vim 中获得代码折叠以使 shell 脚本正常工作

vim - 如何在 Vim 中以读/写模式打开文件?