【问题标题】:Automatic line break within string literal字符串文字中的自动换行符
【发布时间】:2015-09-15 16:12:24
【问题描述】:

当我在 Vim 中编程时,我想防止字符串文字中的换行。换句话说,用set textwidth = 80

testVariable = myFunction(a=var1, b=var2, c=var3, text="This should not break to
                      the next line but does", end="this should be on the
                      next line")

应改为如下包装:

testVariable = myFunction(a=var1, b=var2, c=var3, text="This should not break to the next line but does",
                          end="this should be on the next line")

是否有我可以使用的 vimrc 选项或插件来完成此操作?如果重要的话,我正在用 python 编程。

【问题讨论】:

标签: string vim newline


【解决方案1】:

没有内置的方法可以防止在特定情况下换行,但是您当然可以通过将set formatoptions+=b 添加到您的 vimrc 来让您的生活更轻松。 'formatoptions' 描述 Vim 如何格式化文本。 b 那里有 means,Vim 只会分割比 'textwidth' 更短的行。

这样,您的工作流程将如下所示:

  1. 开始输入您的长字符串。
  2. 当它换行时,退出插入模式并将其全部重新加入一行(EscapekJ;你知道J对吧?)。
  3. 继续输入。 Vim 不会再尝试换行(除非你将它修剪到 'textwidth' 的限制之下。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-28
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-09
    • 2021-09-26
    • 1970-01-01
    相关资源
    最近更新 更多