【问题标题】:How do I fold in vim through blank lines (rspec example)?如何通过空行折叠 vim(rspec 示例)?
【发布时间】:2013-02-10 23:17:47
【问题描述】:

我试图让 vim 以我想要的方式折叠,但是遇到了麻烦。

我在一些测试代码中使用了空格以使其更清晰,我无法让 vim 折叠空白行。

我有什么:

describe 'Troubles' do

  describe 'Home' do

    let( :troubles ) { be_over}

    describe 'Pain' do
      it "shouldn't be this hard" { puts "but it is" }
    end
  end
end

它希望它像这样折叠:

describe 'Troubles' do

  describe 'Home' do
+--- 6  lines: -------------------
  end
end

有什么办法可以做到吗?

这是我的 .vim 折叠设置

set tabstop=2
set shiftwidth=2
set expandtab

set foldmethod=indent
set foldnestmax=10
set nofoldable
set foldlevel=1

【问题讨论】:

    标签: vim folding


    【解决方案1】:

    你用的是什么折叠方法?使用缩进折叠方法对我来说效果很好(它折叠了 5 行,因为第一个是空白的未缩进行。

    set foldmethod=indent
    

    【讨论】:

    • 感谢或快速回复 Eric。其实我已经有那一套了。我在问题中添加了折叠和间距配置以帮助澄清。
    • 我无法找到如何在 vimrc 中修复它,但我设法重现了该问题并在运行时修复它。如果我在 .vimrc 中加载这些设置,我可以重现该问题。如果我重现了问题并在输入文本后运行 :set shiftwidth=2 ,它会按预期工作,但如果我在输入文本之前执行 :set shiftwidth=2 则不会。同样,如果文件已保存并重新打开,则 .vimrc 中的 shiftwidth=2 可以正常工作,并且折叠按预期工作。
    【解决方案2】:

    如果您有兴趣专门为 RSpec 文件折叠,这里是 a little RSpec foldexpr plugin 我在周末整理的。它的功能很大(~150 SLOC),但它以我喜欢的方式处理折叠(例如折叠包含在一个块之后的尾随换行符,这不完全是你的问题,但非常接近)。

    这是您的示例代码的折叠列:

    -    describe 'Troubles' do
    |
    |-     describe 'Home' do
    ||
    ||       let( :troubles ) { be_over}
    ||
    ||-      describe 'Pain' do
    |||        it "shouldn't be this hard" { puts "but it is"}
    |||      end
    ||     end
    |    end
    

    这是折叠后的样子:

    describe 'Troubles' do
    
    - describe 'Home' ---------------------------------------------------- [4] -
    end
    

    【讨论】:

      猜你喜欢
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多