让 Vim 将所有空格显示为一个字符

发布于 2024-11-28 01:43:37 字数 51 浏览 2 评论 0 原文

我找不到一种方法让 Vim 将所有空格显示为一个字符。 我发现的只是制表符、尾随空格等。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(23

暗喜 2024-12-05 01:43:37

正如其他人所说,您可以使用

:set list

which will 结合

:set listchars=...

显示不可见字符。
现在,没有一个显式选项可用于显示空格,但在列表字符中,您可以设置一个字符来显示除空格之外的所有内容。例如,我的看起来像这样

:set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<

,现在,在您使用

:set list

未明确显示为其他内容的所有内容之后,实际上是一个普通的旧空白。

像往常一样,要了解 listchars 的工作原理,请使用帮助。它提供了有关可以显示哪些字符(例如尾随空格)以及如何显示的重要信息:

:help listchars

向其添加切换可能会有所帮助,以便您可以轻松地看到编辑过程中的更改(来源:VIM:将列表设置为 .vimrc 中的切换):

noremap <F5> :set list!<CR>
inoremap <F5> <C-o>:set list!<CR>
cnoremap <F5> <C-c>:set list!<CR>

As others have said, you could use

:set list

which will, in combination with

:set listchars=...

display invisible characters.
Now, there isn't an explicit option which you can use to show whitespace, but in listchars, you could set a character to show for everything BUT whitespace. For example, mine looks like this

:set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<

so, now, after you use

:set list

everything that isn't explicitly shown as something else, is then, really, a plain old whitespace.

As usual, to understand how listchars works, use the help. It provides great information about what chars can be displayed (like trailing space, for instance) and how to do it:

:help listchars

It might be helpful to add a toggle to it so you can see the changes mid editing easily (source: VIM :set list! as a toggle in .vimrc):

noremap <F5> :set list!<CR>
inoremap <F5> <C-o>:set list!<CR>
cnoremap <F5> <C-c>:set list!<CR>
四叶草在未来唯美盛开 2024-12-05 01:43:37

从补丁 7.4.710 开始,您现在可以使用以下命令设置要显示的字符来代替空格列表字符!

:set listchars+=space:␣

因此,要将所有空白字符显示为字符,您可以执行以下操作:

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

完成后,要隐藏不可见的字符,您可以:

:set nolist

讨论邮件列表:https://groups.google.com/forum/?fromgroups#!topic/vim_dev/pjmW6wOZW_Q

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

When you are finished, to hide the non-visible chars you would:

:set nolist

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

川水往事 2024-12-05 01:43:37

:设置列表以启用。

:set nolist 禁用。

:set list to enable.

:set nolist to disable.

嘦怹 2024-12-05 01:43:37

我认为这里的其他答案更全面,但我想我会分享一个我通常用来在视觉上区分制表符和空格的技巧:

:syntax on
:set syntax=whitespace

这些是 空白编程语言 - 选项卡显示为绿色,空格显示为红色。 :)

可以与 :set list 结合使用,正如许多其他答案所提到的,虽然选项卡将显示为 ^I 而没有绿色高亮,但空格将显示为红色。

I think other answers here are more comprehensive, but I thought I'd share a trick I usually use to differentiate tabs and spaces visually:

:syntax on
:set syntax=whitespace

These are syntax highlighting rules for the Whitespace programming language - tabs show in green and spaces in red. :)

Can be combined with :set list as mentioned by many other answers, although the tabs will then show as ^I without a green higlight, but the spaces will show in red.

莫多说 2024-12-05 01:43:37

:set list 会将所有空格显示为一个字符。除了空间之外的所有东西看起来都与其正常状态不同,这意味着如果您仍然看到一个普通的旧空间,那么它确实是一个普通的旧空间。 :)

: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. :)

笔芯 2024-12-05 01:43:37

如果设置:

:highlight Search cterm=underline gui=underline ctermbg=none guibg=none ctermfg=none guifg=none

然后搜索空格,则每个空格字符将显示为下划线字符。

您可以在一个方便的函数中使用此命令来切换空格的“下划线”。

set hls
let g:HLSpace = 1
let g:HLColorScheme = g:colors_name
function ToggleSpaceUnderscoring()
    if g:HLSpace
        highlight Search cterm=underline gui=underline ctermbg=none guibg=none ctermfg=none guifg=none
        let @/ = " "
    else
        highlight clear
        silent colorscheme "".g:HLColorScheme
        let @/ = ""
    endif
    let g:HLSpace = !g:HLSpace
endfunction

将函数映射到快捷键:

nmap <silent> <F3> <Esc>:call ToggleSpaceUnderscoring()<CR>

注意: 在设置颜色方案后在 vimrc 中定义函数。

If you set:

:highlight Search cterm=underline gui=underline ctermbg=none guibg=none ctermfg=none guifg=none

and then perform a search for a space, every space character will be shown as an underline character.

You can use this command in a handy function that toggles "underscoring" of spaces.

set hls
let g:HLSpace = 1
let g:HLColorScheme = g:colors_name
function ToggleSpaceUnderscoring()
    if g:HLSpace
        highlight Search cterm=underline gui=underline ctermbg=none guibg=none ctermfg=none guifg=none
        let @/ = " "
    else
        highlight clear
        silent colorscheme "".g:HLColorScheme
        let @/ = ""
    endif
    let g:HLSpace = !g:HLSpace
endfunction

Map the function to a shortcut key with:

nmap <silent> <F3> <Esc>:call ToggleSpaceUnderscoring()<CR>

NB: Define the function in vimrc after the colorscheme has been set.

苍景流年 2024-12-05 01:43:37

根据当前缓冲区的语法规则,类似这样的内容可能会起作用:

:syn match WhiteSpace / / containedin=ALL conceal cchar=Æ
:setl conceallevel=2 concealcursor=nv

这需要具有 +conceal 功能的 vim 7.3

更新 10/24/2014
对此进行一点扩展。当然可以为锥形字符定义一些突出显示。

  • 您可以配置隐藏字符的外观。对于突出显示,您必须至少配置一次“隐藏”突出显示组(请参阅 :h hl-Conceal 中的帮助。这可以在您的颜色方案中完成,然后您不需要重新配置它但这会影响所有隐藏的字符(例如,如果您的语法脚本隐藏了更多项目,它们将显示为空白字符)。

    :hi Conceal ctermfg=7 ctermbg=NONE guifg=LightGrey guibg=NONE

  • 似乎有一个特殊性,Vim 不会高亮空格,如果语法脚本使用 skipwhite 关键字就没办法了。周围(也许这会被修复,我发布了patch)

  • 似乎有一个补丁,可以自定义如何空格将以 list 模式显示。在撰写本文时,最新的似乎是这个。 (这意味着,您需要构建自己的 Vim 才能使用它)。
  • conceallevelconcealcursor 是窗口本地选项。这意味着它们在不同的窗口中可以不同(并且也可能由文件类型插件或其他插件脚本设置)。
  • 每当重新加载语法定义文件时都需要执行语法突出显示组。这可以使用 BufWinEnterSyntax 甚至 FileType 自动命令来完成。 (我还没有测试哪一个真正有效)。

最后两项意味着,您必须设置一些自动命令来重置语法规则和相应的选项。对于第一个,人们可能希望使用 ColorScheme 自动命令设置突出显示(以便隐藏的字符始终看起来相同,与颜色方案实际设置的内容无关)。对于完整的解决方案,请查看 romainl 答案,这应该会给您一个开始。如果您设置了一个功能,您可以轻松设置一个切换命令来打开或关闭显示特殊突出显示。

更新 10/26/2014 我制作了一个 插件这个问题。

更新 04/22/2015 Vim 中包含了一个补丁,可以使用 list 选项实现这一点。只需设置 set list listchars+=space:␣
此功能自 Vim 7.4.711 起生效

Depending on your syntax rules for the current buffer, something like this could work:

:syn match WhiteSpace / / containedin=ALL conceal cchar=Æ
:setl conceallevel=2 concealcursor=nv

This needs a vim 7.3 with +conceal feature

Update 10/24/2014
To expand a little bit on that. It is of course possible to define some highlighting for the conealed characters.

  • You can configure, how the concealed chars look. For highlighting, you would have to at least once configure the 'Conceal' highlighting group (See the help at :h hl-Conceal This can be done in your colorscheme and then you do not need to reconfigure it again. But this affects all concealed chars (e.g. if your syntax script conceals some more items, they will be displayed as your white space chars). That could look like this:

    :hi Conceal ctermfg=7 ctermbg=NONE guifg=LightGrey guibg=NONE

  • There seems to be a particularity that Vim will not highlight spaces, if the syntax script uses the skipwhite keyword. There will be no way around (perhaps this will be fixed, I posted a patch)

  • There seems to be a patch floating around, that will allow to customize how spaces will look in list mode. The latest one at the time of writing seems to be this one. (This means, you need to built your own Vim to use this).
  • The conceallevel and concealcursor are window local options. That means they can be different in different windows (and will possibly be also set by filetype plugins or other plugin scripts).
  • The syntax highlighting groups need to be executed whenever a syntax definition file is reloaded. This could be done using a BufWinEnteror possibly also a Syntax or even FileType autocommand. (I have not tested which one actually works).

The last two items means, you would have to setup some autocommands that reset the syntax rules and the correesponding options. For the first one, one might want to setup the highlighting using a ColorScheme autocommand (so that the concealed chars always look the same, independent of what a color scheme actually sets up). For a complete solution, look into romainl answer, that should give you a start. If you setup a function, you can easily setup a toggle command to switch displaying special Highlighting on or off.

Update 10/26/2014 I made a plugin out of this question.

Update 04/22/2015 A patch has been included in Vim that makes this possible using the list option. Simply set set list listchars+=space:␣
This works as of Vim 7.4.711

黯然#的苍凉 2024-12-05 01:43:37

我用它

/\s
:set hlsearch

来突出显示空白。它搜索所有空白,然后启用突出显示以使它们弹出。但是,它打印特殊字符。

I use this

/\s
:set hlsearch

to highlight white spaces. It searches for all white spaces, and then enables the highlight to make them pop out. However, it does not print a special character.

半暖夏伤 2024-12-05 01:43:37

如果您所说的空格指的是 ' ' 字符,我的建议只是搜索/替换。正如其他人所暗示的,set list非打印字符更改为在 listchars 中配置的可见字符。

要明确地将空格显示为其他字符,类似于下面的内容应该可以解决问题:

:%s/ /█/g

然后只需撤消更改即可再次返回。

(为了获得 █,我按下了这个确切的按键序列::%s/ /CTRL-KFB/g )

If by whitespaces you mean the ' ' character, my suggestion would just be a search/replace. As the others have hinted, set list changes non printing characters to a visible character that's configured in listchars.

To explicitly show spaces as some other character, something similar to the below should do the trick:

:%s/ /█/g

Then just undo the change to go back again.

(to get the █ I pressed this exact key sequence: :%s/ /CTRL-KFB/g)

猫性小仙女 2024-12-05 01:43:37

要突出显示空格,只需搜索它:

/;

笔记:

  • <空间>意味着只需输入空格字符。
  • 使用 :set hlsearch

    启用搜索结果突出显示

    突出显示空格和标签:

    /[<空格><制表符>]

    删除突出显示的快速方法是搜索其他内容:
    /asdf

    (只需键入任意简短的随机字符列表)

  • To highlight spaces, just search for it:

    /<space>

    Notes:

  • <space> means just type the space character.
  • Enable highlighting of search results with :set hlsearch

    To highlight spaces & tabs:

    /[<space><tab>]

    A quick way to remove the highlights is to search for anything else:
    /asdf

    (just type any short list of random characters)

  • 2024-12-05 01:43:37

    下面的代码基于 Christian Brabandt 的回答,似乎符合 OP 的要求:

    function! Whitespace()
        if !exists('b:ws')
            highlight Conceal ctermbg=NONE ctermfg=240 cterm=NONE guibg=NONE guifg=#585858 gui=NONE
            highlight link Whitespace Conceal
            let b:ws = 1
        endif
    
        syntax clear Whitespace
        syntax match Whitespace / / containedin=ALL conceal cchar=·
        setlocal conceallevel=2 concealcursor=c
    endfunction
    
    augroup Whitespace
        autocmd!
        autocmd BufEnter,WinEnter * call Whitespace()
    augroup END
    

    将这些行附加到您的 ~/.vimrc 并启动一个新的 Vim 会话来查看仍然不完美 魔法发生了。

    随意编辑默认颜色并隐藏字符。


    注意:多种语言的 *FuncBody 语法组中的某些内容会阻止中间点的显示。我(还不知道?)如何使该解决方案更加可靠。

    The code below is based on Christian Brabandt's answer and seems to do what the OP wants:

    function! Whitespace()
        if !exists('b:ws')
            highlight Conceal ctermbg=NONE ctermfg=240 cterm=NONE guibg=NONE guifg=#585858 gui=NONE
            highlight link Whitespace Conceal
            let b:ws = 1
        endif
    
        syntax clear Whitespace
        syntax match Whitespace / / containedin=ALL conceal cchar=·
        setlocal conceallevel=2 concealcursor=c
    endfunction
    
    augroup Whitespace
        autocmd!
        autocmd BufEnter,WinEnter * call Whitespace()
    augroup END
    

    Append those lines to your ~/.vimrc and start a new Vim session to see the still imperfect magic happen.

    Feel free to edit the default colors and conceal character.


    Caveat: something in the *FuncBody syntax group in several languages prevents the middle dot from showing. I don't know (yet?) how to make that solution more reliable.

    场罚期间 2024-12-05 01:43:37

    我没有从现有答案中找到我想要的答案。下面的代码将以亮红色突出显示所有尾随空格。只需将以下内容添加到您的 .vimrc

    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()
    

    I didn't find exactly what I wanted from the existing answers. The code below will highlight all trailing spaces bright red. Simply add the following to your .vimrc

    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()
    
    少女的英雄梦 2024-12-05 01:43:37

    我对这个问题的所有其他答案感到沮丧,因为它们都没有以有用的方式突出空格字符。将空格显示为字符对于空白格式的语言特别有帮助,在这种语言中混合制表符和空格是有害的。

    我的解决方案是显示制表符并在多个空格下划线。它借用了 mrucci 的答案本教程。因为它使用语法突出显示,所以它是持久的:

    set list listchars=tab:\|\ 
    highlight Whitespace cterm=underline gui=underline ctermbg=NONE guibg=NONE ctermfg=yellow guifg=yellow
    autocmd ColorScheme * highlight Whitespace gui=underline ctermbg=NONE guibg=NONE ctermfg=yellow guifg=yellow
    match Whitespace /  \+/
    

    使用它,制表符显示为 | ,空格显示为 _ ,这使得我在混合代码样式时很容易分辨。

    我发现的唯一缺点是此代码片段不会调整背景颜色以匹配上下文(就像在评论中一样)。

    I was frustrated with all of the other answers to this question, because none of them highlight the space character in a useful way. Showing spaces as characters would particularly help for whitespace-formatted languages, where mixing tabs and spaces is harmful.

    My solution is to show tabs and underline multiple spaces. It borrows from mrucci's answer and this tutorial. Because it uses syntax highlighting, it's persistent:

    set list listchars=tab:\|\ 
    highlight Whitespace cterm=underline gui=underline ctermbg=NONE guibg=NONE ctermfg=yellow guifg=yellow
    autocmd ColorScheme * highlight Whitespace gui=underline ctermbg=NONE guibg=NONE ctermfg=yellow guifg=yellow
    match Whitespace /  \+/
    

    Using this, tabs are displayed as | and spaces as _, which makes it very easy to tell when I'm mixing code styles.

    The only downside I've found is that this snippet doesn't adjust background color to match the context (like in a comment).

    小猫一只 2024-12-05 01:43:37

    覆盖 Unicode 空白字符:

    set list
    set listchars=tab:│\ ,nbsp:·
    highlight StrangeWhitespace guibg=Red ctermbg=Red
    " The list is from https://stackoverflow.com/a/37903645 (with `\t`, `\n`, ` `, `\xa0` removed):
    call matchadd('StrangeWhitespace', '[\x0b\x0c\r\x1c\x1d\x1e\x1f\x85\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]')
    

    结果:

    • 只有序数空格 (U+0020) 看起来像序数空格 (" ")。
    • 该选项卡 (U+0009) 看起来像“│ ”(两个字符:一个长管道,然后是一个序号空格;它们在 colorscheme murphy 中为灰色)。
    • 不间断空格 (U+00A0) 看起来像“·”(一个字符;在 colorscheme murphy 中为灰色)。
    • 任何其他空白字符看起来都像红色空格(“ ”)。

    To cover Unicode whitespace characters:

    set list
    set listchars=tab:│\ ,nbsp:·
    highlight StrangeWhitespace guibg=Red ctermbg=Red
    " The list is from https://stackoverflow.com/a/37903645 (with `\t`, `\n`, ` `, `\xa0` removed):
    call matchadd('StrangeWhitespace', '[\x0b\x0c\r\x1c\x1d\x1e\x1f\x85\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]')
    

    The result:

    • Only the ordinal space (U+0020) looks like an ordinal space (" ").
    • The tab (U+0009) looks like "│ " (two characters: a long pipe and then an ordinal space; they are gray in colorscheme murphy).
    • The non-breaking space (U+00A0) looks like "·" (one character; it's gray in colorscheme murphy).
    • Any other whitespace character looks like a red space (" ").
    梦幻之岛 2024-12-05 01:43:37

    上面的所有答案都试图使空格在 vim 中可见。如果你真的坚持将可见空间设置为点,还有另一种方法......

    如果在 vim 中无法完成,请完全更改你的字体。我复制了 Ubuntu One Mono 字体并使用 FontForge 对其进行了编辑。请记住更改字体的全名、系列、首选系列、兼容全名(在 FontFoge 中,它位于字体信息中的 TTF 名称下),以便将其作为单独的字体。
    只需编辑空格字符以在中间有一个点并将字体保存到 ~/.fonts
    现在你可以将它用于你的 gvim 或整个终端......
    我复制了“!”字符,删除线并将点移到中间。花了5分钟多一点...

    注意:更改空格字符(0x20)会导致整个vim屏幕上有点的不便...(但它会将空格与制表符分开...)

    all of the answers above try to make spaces visible from within vim. If you really insist on having visible spaces as dots, there's another approach...

    If it cannot be done in vim, change your font entirely. I copied the Ubuntu One Mono font and edited it using FontForge. Remember to change the font's fullname, family, preferred family, compatible full (in FontFoge it's under TTF Names in the font info), in order to have it as a separate font.
    Simply edit the space character to have a dot in the middle and save the font to ~/.fonts
    Now you can use it for your gvim or the entire terminal...
    I copied the "!" character, removed the line and moved the dot to the middle. It took a little more than 5 minutes...

    Note: changing the space character (0x20) results in the inconvenience of having dots on the entire vim screen... (but it will separate the spaces from tabs...)

    一杆小烟枪 2024-12-05 01:43:37

    这些 hack 作为注释保留在 .vimrc 中,因此在 shell 中,只需:

    echo '
      " how-to see the non-visible while spaces
      " :set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣
      " set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
      " :set list
      " but hei how-to unset the visible tabs ?!
      " :set nolist
      ' >> ~/.vimrc
    

    Keep those hacks in the .vimrc as comments, so in the shell, simply :

    echo '
      " how-to see the non-visible while spaces
      " :set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣
      " set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
      " :set list
      " but hei how-to unset the visible tabs ?!
      " :set nolist
      ' >> ~/.vimrc
    
    岁月如刀 2024-12-05 01:43:37

    您可以用来

    :set list
    

    真正查看线条的结构。您将明确看到制表符和换行符。当你看到一片空白时,它确实是一片空白。

    You could use

    :set list
    

    to really see the structure of a line. You will see tabs and newlines explicitly. When you see a blank, it's really a blank.

    淡写薰衣草的香 2024-12-05 01:43:37
    :match CursorLine /\s\+/
    

    避免了“你必须搜索空间才能让它们显示”的情况,但不能将 afaict 配置为对空间执行非突出显示的操作。 CursorLine 可以是任何高亮组,在默认主题中它是一个简单的下划线。

    :match CursorLine /\s\+/
    

    avoids the "you have to search for spaces to get them to show up" bit but afaict can't be configured to do non-hilighting things to the spaces. CursorLine can be any hilighting group and in the default theme it's a plain underline.

    末蓝 2024-12-05 01:43:37

    我喜欢用特殊字符来显示空白,这样更清晰。甚至可以切换的地图也是一个关键功能,用于快速检查。

    您可以在自 2004 年以来未更新的旧 vim 脚本中找到此功能:

    vim-scripts/ [电子邮件受保护]

    感谢项目 vim-scripts< /a> 和vundle 你可以通过这个插件恢复活力

    vim-scripts/cream-showinvisibles@github

    更好的是,我的两分钱是添加一个 可配置的快捷方式(而不是预定义的F4),

    因此将其添加到~/.vimrc

    Plugin 'albfan/cream-invisibles'
    
    let g:creamInvisibleShortCut = "<F5>" "for my F4 goto next error
    

    在 vi​​m 上安装插件

    :PluginInstall
    

    就可以了 去

    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/[email protected]

    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

    固执像三岁 2024-12-05 01:43:37

    搜索

    :set hlsearch 
    

    突出显示.vimrc 中的

    ,即搜索空格制表符和回车符

    / \|\t\|\r
    

    或搜索所有空白字符或

    /\s
    

    搜索所有非空白字符(空白字符未显示,因此您会看到空白字符在单词之间,但不是尾随空白字符)

    /\S
    

    以显示所有尾随空白字符 - 在行尾

    /\s$
    

    highlight search

    :set hlsearch 
    

    in .vimrc that is

    and search for space tabs and carriage returns

    / \|\t\|\r
    

    or search for all whitespace characters

    /\s
    

    of search for all non white space characters (the whitespace characters are not shown, so you see the whitespace characters between words, but not the trailing whitespace characters)

    /\S
    

    to show all trailing white space characters - at the end of the line

    /\s$
    
    伴我老 2024-12-05 01:43:37
    :se list
    :se nolist
    

    :se 就足够了,不需要 :set

    :se list
    :se nolist
    

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

    无人问我粥可暖 2024-12-05 01:43:37

    您还可以突出显示空格(用块替换空格):(

    :%s/ /█/g
    

    在写入之前撤消它)

    you can also highlight the spaces (replacing the spaces with a block):

    :%s/ /█/g
    

    (before writing undo it)

    A君 2024-12-05 01:43:37

    将其添加到我的 .vimrc 对我有用。只要确保没有其他任何冲突即可。

    autocmd VimEnter * :syn match space /\s/
    autocmd VimEnter * :hi space ctermbg=lightgray ctermfg=black guibg=lightgray guifg=black
    

    Adding this to my .vimrc works for me. Just make sure you don't have anything else conflicting..

    autocmd VimEnter * :syn match space /\s/
    autocmd VimEnter * :hi space ctermbg=lightgray ctermfg=black guibg=lightgray guifg=black
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文