1

我试图让 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
4

2 回答 2

3

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

set foldmethod=indent
于 2013-02-10T23:40:22.773 回答
1

如果你有兴趣专门为 RSpec 文件折叠,这里是我在周末拼凑的一个小 RSpec foldexpr 插件。它的作用很大(~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-08-07T07:53:37.843 回答