【问题标题】:Word Wrap in Vim (preserving indentation) in Latex documentLatex 文档中 Vim 中的自动换行(保留缩进)
【发布时间】:2019-02-21 19:34:09
【问题描述】:

我只是在看this 的帖子,它描述了如何在 vim 中包装整个单词。我正在寻找一种方法来键入缩进,或者在我的情况下,缺少它。

我通常用V 选择几行,然后按gq 重新格式化并重新换行。

比方说,我有以下文件

 *Inside of window                        *Outside of window
|---------------------------------------|    
|This is a bla like of text that will wr|ap here                            
|can you see the wrap                   |
|                                       |
|---------------------------------------|

结果将是:

 *Inside of window                        *Outside of window
|---------------------------------------|    
|This is a bla like of text that will   |                            
|wrap here can you see the wrap         |
|                                       |
|---------------------------------------|

到目前为止一切顺利。

现在假设,我有以下带有一些乳胶标签的文档

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\begin{abstract}                       |
|This is a bla like of text that will wr|ap here                            
|can you see the wrap                   |
|\end{abstract}                         |
|                                       |
|---------------------------------------|

结果如下,其中下一行包含不受欢迎的\t

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\begin{abstract}                       |
|This is a bla like of text that will   |
|    wrap here can you see the wrap     |
|\end{abstract}                         |
|                                       |
|---------------------------------------|

但是,我的目标是得到如下结果,下一行没有不受欢迎的\t

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\begin{abstract}                       |
|This is a bla like of text that will   |
|wrap here can you see the wrap         |
|\end{abstract}                         |
|                                       |
|---------------------------------------|

我尝试将set breakindent 添加到我的.vimrc,但没有成功。目前这些是我使用的关于包装的行。

set wrap                                    " Wrap                                 
set textwidth=79                            " Default Text Width

【问题讨论】:

    标签: vim word-wrap tex


    【解决方案1】:

    Latex 的缩进由GetTeXIndent() 函数确定(可以通过:setlocal indentexpr? 找到)。 $VIMRUNTIME/indent/tex.vim 中的相应脚本在其标题中有文档。它提到(除其他外)影响环境缩进的配置设置。

    " * g:tex_noindent_env
    "
    "   A list of environment names. separated with '\|', where no indentation is
    "   required. The default is 'document\|verbatim'.
    

    如果您在此处添加 \begin{...} 项目(通过将配置放入您的 ~/.vimrc),则不会发生额外的缩进:

    let g:tex_noindent_env .= '\|begin'
    

    警告:我对 Latex 语法知之甚少;这可能会对其他地方的格式化产生不必要的副作用。阅读整个缩进文档以了解调整它的选项。

    【讨论】:

    • 我在尝试此解决方案时遇到此错误。 E121: Undefined variable: g:tex_noindent_env
    • 是的,因为它附加到默认配置;答案假设您已经在编辑乳胶文档。缩进脚本需要首先是:sourced,或者你将整个配置值复制到你的vimrc中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    相关资源
    最近更新 更多