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

cha*_*des 7 vim go vim-syntax-highlighting

出于某种原因,似乎带有Go文件的vim的默认设置是用红色突出显示尾随空格.在某种程度上这很好,但大多数情况下我发现它很烦人,因为每次我输入一个空格时它都会以红色突出显示.有没有办法阻止这种行为?我只用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
Run Code Online (Sandbox Code Playgroud)

ryu*_*iro 8

go.vimVim语法文件:

"   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.
Run Code Online (Sandbox Code Playgroud)

放入你的.vimrc

let g:go_highlight_trailing_whitespace_error=0
Run Code Online (Sandbox Code Playgroud)

还有以下其他选择:

"   - 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.
Run Code Online (Sandbox Code Playgroud)

如果你仍然喜欢突出显示尾随空格而不是在打字过程中,你可以试试

au InsertEnter *.go match goSpaceError /\s\+\%#\@<!$/
au InsertLeave *.go match goSpaceError /\s\+$/
Run Code Online (Sandbox Code Playgroud)

阅读更多内容突出显示来自wikia的不需要的空格.

  • 在我的系统上,我收到“E149:抱歉,vim-go 没有帮助”。你的简短评论不仅无益,而且是错误的。 (2认同)