简体   繁体   English

在gvim中显示空白字符

[英]Show whitespace characters in gvim

Is there an easy way to display whitespace characters such as space and tab in gvim? 有没有一种简单的方法可以在gvim中显示空格和制表符等空白字符? Something like what is implemented in Gedit, Geany, Komodo, and other GUI editors where (when the option is turned on) spaces show as a muted or greyed-out '.' 类似于Gedit,Geany,Komodo和其他GUI编辑器中实现的内容(当选项打开时)空格显示为静音或灰色'。' and tabs as '-->'. 和标签为' - >'。

Check out listchars and list options in Vim. 查看Vim中的listcharslist选项。 An example use of this feature: 此功能的一个示例用法:

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

You can use any characters you wish if you enable Unicode first 如果先启用Unicode,则可以使用任何所需的字符

set encoding=utf-8

One line I use (put in ~/.vimrc ): 我使用的一行(放入~/.vimrc ):

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

Learn more about this setting at http://vim.wikia.com/wiki/Highlight_unwanted_spaces 有关此设置的详情,请访问http://vim.wikia.com/wiki/Highlight_unwanted_spaces

The color of these characters is controlled by your color scheme. 这些字符的颜色由您的配色方案控制。

Here are some of my settings pertaining whitespace. 以下是我的一些关于空白的设置。

Use F11 to toggle between displaying whitespace characters or not: 使用F11在显示空格字符之间切换:

noremap <F11> :set list!<CR>

How to show whitespace characters when list is set: 如何在设置list时显示空白字符:

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

Highlight special characters in yellow: 突出显示黄色的特殊字符:

highlight SpecialKey term=standout ctermbg=yellow guibg=yellow

Highlight redundant spaces (spaces at the end of the line, spaces before or after tabs): 突出显示冗余空格(行尾的空格,制表符之前或之后的空格):

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

Hope these help! 希望这些帮助!

This works well for me: 这适合我:

"trailing white space detection
highlight WhitespaceEOL ctermbg=yellow guibg=yellow
match WhitespaceEOL /\s\+$/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM