【问题标题】:Vim line wrap: how to insert backslash '\' automatically when wrapping a line?Vim换行:换行时如何自动插入反斜杠'\'?
【发布时间】:2023-03-06 04:03:01
【问题描述】:

假设我:set tw=5,在包装以下“长”行时:

a = b + c

变成:

a = b
+ c

但我希望它是:

a = b \
+ c

如果在下一行之前插入智能缩进甚至更好,如下所示:

a = b \
  + c

怎么做?

【问题讨论】:

    标签: vim indentation


    【解决方案1】:

    您正在寻找的是:h formatexpr

    您需要定义一个表达式来检查您在mode() ==# 'i' 中的模式,然后执行您希望发生的更改。返回非零将使用默认表达式。

    例如

    set formatexpr=FormatFoo()
    function! FormatFoo()
      if mode() ==# 'i'
        echom "insertmode line wrap"
        return 1
      else
        echom "normalmode line wrap"
        return 1
      endif
    endfunction
    

    【讨论】:

      猜你喜欢
      • 2013-11-04
      • 2014-09-09
      • 2011-09-06
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2022-08-07
      • 2012-04-14
      • 2012-06-16
      相关资源
      最近更新 更多