vim - 停止在 Vim 中高亮显示 Go 文件的尾随空格

标签 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

最佳答案

来自 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来自 wikia .

关于vim - 停止在 Vim 中高亮显示 Go 文件的尾随空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40945136/

相关文章:

go - 如何使用反射将结构值转换为结构指针

Vim 语法文件 : defining keywords to ignore whitespace

go - AM2320 传感器 : CRCs doesn't match, 来自传感器的 CRC(0)

go - 同步两个大小为 1 的 goroutines

vim - 文件保存期间语法高亮随机消失

vim - 在 vim 中使用带有 synmaxcol 的折叠

linux - YCM 生成器中的 PROJECT_DIRECTORY 在哪里

linux - NeoVim 通过 ctrl + q 键绑定(bind)需要两秒退出

ruby - 将 VIM 插件添加到 Janus 设置中

vim - 在插入模式下从系统剪贴板粘贴,然后重复 (.) 失败