在gvim中显示空白字符

问题描述 投票:37回答:4

有没有一种简单的方法可以在gvim中显示空格和制表符等空白字符?类似于Gedit,Geany,Komodo和其他GUI编辑器中实现的内容(当选项打开时)空格显示为静音或灰色'。'和标签为' - >'。

vim whitespace
4个回答
37
投票

查看Vim中的listcharslist选项。此功能的一个示例用法:

" part of ~/.vimrc
" highlight tabs and trailing spaces
set listchars=tab:>-,trail:-
set list

29
投票

如果先启用Unicode,则可以使用任何所需的字符

set encoding=utf-8

我使用的一行(放入~/.vimrc):

set list listchars=tab:→\ ,trail:·

http://vim.wikia.com/wiki/Highlight_unwanted_spaces了解有关此设置的更多信息

这些字符的颜色由您的配色方案控制。


6
投票

以下是我的一些关于空白的设置。

使用F11在显示空格字符之间切换:

noremap <F11> :set list!<CR>

设置list时如何显示空白字符:

set listchars=eol:$,tab:>-,trail:.,extends:>,precedes:<,nbsp:_

突出显示黄色的特殊字符:

highlight SpecialKey term=standout ctermbg=yellow guibg=yellow

突出显示冗余空格(行尾的空格,制表符之前或之后的空格):

highlight RedundantSpaces term=standout ctermbg=Grey guibg=#ffddcc    
call matchadd('RedundantSpaces', '\(\s\+$\| \+\ze\t\|\t\zs \+\)\(\%#\)\@!')

希望这些帮助!


0
投票

这适合我:

"trailing white space detection
highlight WhitespaceEOL ctermbg=yellow guibg=yellow
match WhitespaceEOL /\s\+$/
© www.soinside.com 2019 - 2024. All rights reserved.