登录
首页 >  Golang >  Go问答

在 Vim 中编辑 Go 源文件时如何禁用空格突出显示?

来源:stackoverflow

时间:2024-04-25 17:42:36 235浏览 收藏

本篇文章给大家分享《在 Vim 中编辑 Go 源文件时如何禁用空格突出显示?》,覆盖了Golang的常见基础知识,其实一个语言的全部知识点一篇文章是不可能说完的,但希望通过这些问题,让读者对自己的掌握程度有一定的认识(B 数),从而弥补自己的不足,更好的掌握它。

问题内容

在 vim 中编辑 go 源文件时如何禁用空格突出显示?

此外,为什么 vim 会在 go 源文件中突出显示空格,而在 python 源文件中却不会这样做 - 是根据文件扩展名启用空格突出显示,例如.go 还是 .py

vim 版本:

nlykkei:~$ vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 16 2019 18:46:24)
Included patches: 1-503, 505-680, 682-1312
Compiled by [email protected]
Normal version without GUI.  Features included (+) or not (-):
+acl               +extra_search      -mouse_netterm     -tag_old_static
-arabic            -farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    -tcl
+autochdir         +find_in_path      -mouse_urxvt       -termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
-balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
+builtin_terms     -gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        -toolbar
-clientserver      +job               -perl              +user_commands
-clipboard         +jumplist          +persistent_undo   -vartabs
+cmdline_compl     -keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      -langmap           -profile           +visual
+comments          +libcall           +python/dyn        +visualextra
-conceal           +linebreak         -python3           +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          -rightleft         +wildmenu
+cursorshape       -lua               +ruby/dyn          +windows
+dialog_con        +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             -X11
+digraphs          +modify_fname      +smartindent       -xfontset
-dnd               +mouse             +startuptime       -xim
-ebcdic            -mouseshape        +statusline        -xpm
-emacs_tags        -mouse_dec         -sun_workshop      -xsmp
+eval              -mouse_gpm         +syntax            -xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa

解决方案


它不是突出显示,也不是任何插件。这是所谓的“空白错误”的语法着色——不应该出现的尾随空白。它来自内置的 syntax/go.vim

您可以通过设置各种全局 go_* 变量来自定义突出显示。 go.vim 顶部的块注释解释了它们:

" Options:
"   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. You can also write:
"     let OPTION_NAME = 1
"   to enable particular options. At present, all options default to on.
"
"   - 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.
"   - g:go_highlight_trailing_whitespace_error
"     Highlights trailing white space.

注释:

  • g: 全局设置选项。
  • 使用 :set syntax 检查当前语言。
  • 请参阅 filetype.vim 了解文件名到语言的映射。

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《在 Vim 中编辑 Go 源文件时如何禁用空格突出显示?》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>