Vim:如何手動折疊縮排塊?

Vim:如何手動折疊縮排塊?

如何使用 vim 中的手動折疊以與當前行(遊標所在的行)相同的縮排折疊每一行?

基本上,有時我需要 Vim 折疊東西,就像 Vim 在 時所做的那樣 foldmethod=indent,但我更喜歡使用它foldmethod=manual並且不會改變它。

例如:

function f(x)

  while (x > a)
    foo = bar
    someStuff() // suppose cursor is here
    x = foo + a
  end

  if (x < b)
    x = b // this line should not be indented
  end
end

在這種情況下,它應該將行折疊foo = barx = foo + a

答案1

您可以用來:-1,+1norm zF指定要折疊的行的相對範圍。 (在上面 1 行和下面 1 行的情況下,您可以省略1該命令中的 s 並僅使用:-,+norm zF)。

如果您願意安裝插件,那麼有 vim 縮排對象它給了“縮排物件”,例如nside ndent 和 round iindent ii等等ai)。然後你可以做類似的事情。aizfii

相關內容