在vim中显示尾随空格

在vim中显示尾随空格,vim,indentation,Vim,Indentation,我在.vimrc中设置了以下选项 set listchars=tab:▸\ ,trail:· set list 并希望在代码中使用空格制表的地方看到点(我使用空格,而不是制表符)。 但是,结果不同: 你能推荐一下如何达到预期的效果吗?谢谢 你应该检查一下。我正在使用match命令解决方案: :highlight ExtraWhitespace ctermbg=red guibg=red :match ExtraWhitespace /\s\+$/ 本页还提供了我个人没有尝试过的内容 并希望

我在.vimrc中设置了以下选项

set listchars=tab:▸\ ,trail:·
set list
并希望在代码中使用空格制表的地方看到点(我使用空格,而不是制表符)。 但是,结果不同:

你能推荐一下如何达到预期的效果吗?谢谢

你应该检查一下。我正在使用
match
命令解决方案:

:highlight ExtraWhitespace ctermbg=red guibg=red
:match ExtraWhitespace /\s\+$/
本页还提供了我个人没有尝试过的内容

并希望在代码中使用空格制表的地方看到点(我使用空格,而不是制表符)

实际上这是另一种方式,
tab
选项用于在插入制表符(\t)而不是空格时显示字符。 而
trail
用于在行尾显示尾随空格

您似乎有一条带尾随空格的空行,并且正确显示了点

如果您只使用空格,则不会使用或显示
选项卡
选项。

该插件包含了@icecrime答案中引用的许多提示。它还有一些漂亮的配置选项


我只是为了使用这个插件而安装的,从各方面考虑,我对自己的生活都很满意。

根据icecrime发布的链接,我发现这个插件非常有效

" Be clever about highlighting trailing whitespace (don't highlight it if we are
" in 'insert' mode and the cursor is at the end of the line). Also (regardless
" of 'insert' mode), highlight any tabs that immediately follow space(s).
" EOLWS and EOLWSInsert are colour group names; the latter being toned-down to
" make editing in 'insert' mode easier on the eye
autocmd InsertEnter * match EOLWS // | match EOLWSInsert /\s\+\%#\@<!$\| \+\ze\t/
autocmd InsertLeave * match EOLWSInsert // | match EOLWS /\s\+$\| \+\ze\t/
autocmd WinEnter,BufWinEnter,WinNew * match EOLWS /\s\+$\| \+\ze\t/

" Disable syntax-specific trailing space error handling because it conflicts
" with the above, mostly because the syntax highlighting doesn't take account of
" whether 'insert' mode is active or not. There are other '*_no_trail_space_error'
" settings - refer to syntax files in $VIMRUNTIME/syntax/
let c_no_trail_space_error = 1
let java_no_trail_space_error = 1
“在突出显示尾随空白方面要聪明(如果需要,请不要突出显示)
“在“插入”模式下,光标位于行的末尾)。也(不管
“对于“插入”模式),突出显示紧跟空格的任何选项卡。
“EOLWS和EOLWSInsert是颜色组名称;后者被调低到
“使在“插入”模式下进行编辑更直观

autocmd InsertEnter*匹配EOLWS/|匹配EOLWSInsert/\s\+\%\\\@以突出显示尾随空白字符:

:设置hlsearch
,然后


/\s\+$

谢谢。这确实是我要找的。但是这个匹配有时会在做一些操作后被重置。如何始终保持它打开?在你的
.nvimrc
中输入。没有colons@Rocky您可以使用:2match{group}/{pattern}/我还建议添加链接页面中给出的
autocmd-bufwenter*match ExtraWhitespace/\s\+$/autocmd-InsertEnter*match ExtraWhitespace/\s\+\%\\\@以防止在插入模式下突出显示。请注意,将这些行放在
colorscheme…
命令后面很重要