Make Vim show ALL white spaces as a character

2019-01-03 19:21发布

I can't find a way to make Vim show all white spaces as a character. All I found was about tabs, trailing spaces etc.

标签: vim vi
23条回答
男人必须洒脱
2楼-- · 2019-01-03 19:24

As of patch 7.4.710 you can now set a character to show in place of space using listchars!

:set listchars+=space:␣

So, to show ALL white space characters as a character you can do the following:

:set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣
:set list

Discussion on mailing list: https://groups.google.com/forum/?fromgroups#!topic/vim_dev/pjmW6wOZW_Q

查看更多
太酷不给撩
3楼-- · 2019-01-03 19:25

I found adding these to my .vimrc worked most effectively

highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
查看更多
太酷不给撩
4楼-- · 2019-01-03 19:26

I like using special characters to show whitespace, is more clear. Even a map to toggle is a key feature, for a quick check.

You can find this features in an old vim script not updated since 2004:

vim-scripts/cream-showinvisibles@vim.org

Thanks to project vim-scripts and vundle you can come back to life this plugin

vim-scripts/cream-showinvisibles@github

Even better, my two cents on this is to add a configurable shortcut (instead of predefined F4)

so add this to ~/.vimrc

Plugin 'albfan/cream-invisibles'

let g:creamInvisibleShortCut = "<F5>" "for my F4 goto next error

install plugin on vim

:PluginInstall

and there you go

查看更多
▲ chillily
5楼-- · 2019-01-03 19:26
:se list
:se nolist

:se is enough, :set isn't needed.

查看更多
狗以群分
6楼-- · 2019-01-03 19:31

:set list to enable.

:set nolist to disable.

查看更多
时光不老,我们不散
7楼-- · 2019-01-03 19:31

:set list will show all whitespaces as a character. Everything but a space will look different than its normal state, which means that if you still see a plain old space, it's really a plain old space. :)

查看更多
登录 后发表回答