vimtex: force } 和 { 不跳过空行

vimtex: force } and { not to skip empty lines

当我使用 }{ 时,vimtex+vim 在文档中有点随机跳转,跳过几个空行。见下文。

如何恢复不跳过空行的默认 vim 行为?

使用

查找}是否有任何映射
:map }

现在,您可以取消映射找到的任何映射

:unmap }

如果你想把它放在你的 .vimrc 中,我建议你把它放在那个插件的 after 目录中。

喜欢~/.vim/after/plugin

简答

跳过随机发生的事实表明空行并不是真正的空行。它们包含白色space 或其他特殊字符。

将光标移动到这些 'empty' 行并按 $ 以查看它们是否真的为空。


如何避免此类问题:

(是的,其他人也有你的问题。)

使vim显示白色space个字符
Vim 有办法显示这些字符。使用 set list 并定义 listchars。来自 vim listchars 的帮助:

    Strings to use in 'list' mode and for the :list command.  It is a
    comma separated list of string settings. 
    [...]
                                                    lcs-space
      space:c       Character to show for a space.  When omitted, spaces
                    are left blank.
                                                    lcs-trail
      trail:c       Character to show for trailing spaces.  When omitted,
                    trailing spaces are blank.  Overrides the "space"
                    setting for trailing spaces.

有关详细信息,请参阅 :help :list:help listchars


高亮尾随白色space
我发现总是为任何 space 显示一个字符非常烦人,而且我的眼睛太糟糕了,看不到行尾的小点(用于尾随 spaces)。因此我使用高亮组来显示所有尾随的白色 space 字符:

" Show trailing whitespace
    highlight ExtraWhitespace ctermbg=red       " define highlight group                      
    match ExtraWhitespace /\s\+$/               " define pattern
    autocmd BufWinEnter * match ExtraWhitespace /\s\+$/         " apply match to all buffers
    autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/  " don't match while in insert 
    autocmd InsertLeave * match ExtraWhitespace /\s\+$/
    autocmd BufWinLeave * call clearmatches()                   " It's good for the RAM

自动删除尾随白色space
还有一种方法可以在写入缓冲区时自动删除这些字符——但有一些注意事项(想想 markdown 的双尾随白色 space 换行符)。

Vim wiki 有很好的解释。

最简单(但可能不是最好)的解决方案是添加

 autocmd BufWritePre * %s/\s\+$//e

到您的 .vimrc 或相应的 ftplugin 文件。 我个人在我的 vimrc 中有一个功能并针对文件类型禁用它,而我没有 want/need 它。


您可能还对Make { and } ignore lines containing only whitespace

感兴趣

免责声明
可能有些字符不是白色 space,但默认情况下 vim 也不会显示。我从来没有遇到过这个问题,但我在 'Short Answer' 下所说的仍然适用。