英文:
Stop highlighting trailing whitespace for Go files in Vim
问题
似乎在使用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
英文:
For some reason it seems the default for vim with Go files is to highlight trailing whitespace in red. In a way this is nice, but mostly I find it annoying because every time I type a space it starts as a red highlight. Is there a way to stop this behavior? I've only experienced this with Go files. Below is my vimrc, but I don't think I put anything there that would affect it.
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
答案1
得分: 8
从go.vim
Vim语法文件中:
> " 有一些用于自定义高亮的选项;推荐的设置是默认值,但你可以在你的~/.vimrc文件中写入:
> " let OPTION_NAME = 0
> " 来禁用特定选项。
在你的.vimrc文件中添加以下内容:
let g:go_highlight_trailing_whitespace_error=0
还有其他选项:
> " - g:go_highlight_array_whitespace_error
> " 高亮显示"[]"后的空白字符。
> " - g:go_highlight_chan_whitespace_error
> " 高亮显示不符合标准样式的通信操作符周围的空白字符。
> " - g:go_highlight_extra_types
> " 高亮显示常用的库类型(如io.Reader等)。
> " - g:go_highlight_space_tab_error
> " 高亮显示空格后跟随制表符的实例。
如果你仍然喜欢高亮显示尾部空白字符,但不希望在输入时显示,你可以尝试以下设置:
au InsertEnter *.go match goSpaceError /\s\+\%#\@<!$/
au InsertLeave *.go match goSpaceError /\s\+$/
在Highlight unwanted spaces页面的wikia上阅读更多信息。
英文:
From go.vim
Vim syntax file:
> " 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.
Put in your .vimrc
let g:go_highlight_trailing_whitespace_error=0
There are these other options:
> " - 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.
If you still like the highlighting of trailing whitespaces but not during the typing, you can try
au InsertEnter *.go match goSpaceError /\s\+\%#\@<!$/
au InsertLeave *.go match goSpaceError /\s\+$/
Read more in Highlight unwanted spaces from wikia.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论