处理BufRead Auto命令时检测到unix vim错误

2024-09-25 08:35:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个新的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

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

" 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文件:

^{pr2}$

Tags: 文件代码用户pymatch错误line指南
3条回答

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

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

au BufNewFile, BufRead *.py

而不是au BufNewFile,BufRead *.py 谨致问候

或者从here

" Use the below highlight group when displaying bad whitespace is desired.
highlight BadWhitespace ctermbg=red guibg=red

" Display tabs at the beginning of a line in Python mode as bad.
au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/

" Make trailing whitespace be flagged as bad.
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/

命令:

match BadWhitespace /\s\+$/

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

^{pr2}$

或者定义一个BadWhitespace高亮显示组。一种可能的颜色组合是:

:highlight BadWhitespace ctermfg=16 ctermbg=253 guifg=#000000 guibg=#F8F8F0

在使用BadWhitespace的autocmd之前添加这行代码。在

相关问题 更多 >