在 Vim 中停止突出显示 Go 文件的尾随空格

Stop highlighting trailing whitespace for Go files in Vim

出于某种原因,Go 文件 vim 的默认设置似乎是用红色突出显示结尾的白色 space。在某种程度上这很好,但大多数时候我觉得它很烦人,因为每次我输入 space 它都会以红色突出显示开始。有没有办法阻止这种行为?我只在 Go 文件中遇到过这种情况。下面是我的 vimrc,但我认为我没有放任何会影响它的东西。

set nocompatible
syntax on
set autoindent
set tabstop=4 softtabstop=0
autocmd FileType go set tabstop=8 softtabstop=0
set formatoptions=tcroql
set relativenumber
set incsearch
set hlsearch
set smartindent
filetype indent on

来自 go.vim Vim 语法文件:

"   There are some options for customizing the highlighting; the recommended
"   settings are the default values, but you can write:
"     let OPTION_NAME = 0
"   in your ~/.vimrc file to disable particular options.

放入你的.vimrc

let g:go_highlight_trailing_whitespace_error=0

还有这些其他选项:

"   - g:go_highlight_array_whitespace_error
"     Highlights white space after "[]".
"   - g:go_highlight_chan_whitespace_error
"     Highlights white space around the communications operator that don't
"     follow the standard style.
"   - g:go_highlight_extra_types
"     Highlights commonly used library types (io.Reader, etc.).
"   - g:go_highlight_space_tab_error
"     Highlights instances of tabs following spaces.

如果您仍然喜欢尾随空格的突出显示但在键入过程中不喜欢,您可以尝试

au InsertEnter *.go match goSpaceError /\s\+\%#\@<!$/
au InsertLeave *.go match goSpaceError /\s\+$/

Highlight unwanted spaces from wikia 阅读更多内容。