Stop trailing whitespace for Go files in Vim

For some reason, it seems that by default for vim with Go files, you should highlight red spaces in spaces. In some ways, this is good, but mostly I find it annoying because every time I type a space, it starts as a red highlight. Is there any way to stop this behavior? I only experienced this with Go files. Below is my vimrc, but I do not think that 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 
+5
source share
1 answer

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. 

Insert your .vimrc

 let g:go_highlight_trailing_whitespace_error=0 

The options are as follows:

 " - 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 to highlight trailing spaces, but not during input, you can try

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

Read more in Highlight unwanted spaces from wikia .

+7
source

Source: https://habr.com/ru/post/1260750/


All Articles