首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >处理BufRead自动命令时检测到unix vim错误

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

Stack Overflow用户
提问于 2018-02-19 23:48:08
回答 4查看 7.7K关注 0票数 10

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

我遇到的问题是在.py文件上启动vim时收到这个错误:Error detected while processing BufRead Auto commands for "*.py": E28: No such highlight group name: BadWhitespace

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

代码语言:javascript
复制
" 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文件:

代码语言:javascript
复制
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>
EN

回答 4

Stack Overflow用户

发布于 2019-01-08 05:20:42

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

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

代码语言:javascript
复制
au BufNewFile, BufRead *.py

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

票数 27
EN

Stack Overflow用户

发布于 2018-02-20 02:28:40

命令:

代码语言:javascript
复制
match BadWhitespace /\s\+$/

如果定义了BadWhitespace突出显示组,则将突出显示尾部空白。要检查它是否已定义,请执行:highlight BadWhitespace。如果未定义,则可以使用默认高亮显示组,例如:

代码语言:javascript
复制
match Cursor /\s\+$/

或者定义一个BadWhitespace加亮组。可能的颜色组合是:

代码语言:javascript
复制
:highlight BadWhitespace ctermfg=16 ctermbg=253 guifg=#000000 guibg=#F8F8F0

将此行代码添加到使用BadWhitespace的autocmd之前。

票数 7
EN

Stack Overflow用户

发布于 2019-10-26 12:00:54

问题出在多个set。下面这行中的第一个set

\ set tabstop=4

是命令,并且所有后面的set都被视为参数。

它应该看起来像这样:

代码语言:javascript
复制
au BufNewFile,BufRead *.py
    \ set tabstop=4
    \ softtabstop=4
    \ shiftwidth=4
    \ textwidth=79
    \ expandtab
    \ autoindent
    \ fileformat=unix
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48869590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档