Vim中基于缩进级别的标记块

2024-10-03 04:31:21 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有可能在Vim中根据已经存在的缩进标记块?类似于v{。在

它对于使用空格敏感语法的编程语言(如Haskell和Python)非常有用。在

例如,在此函数中标记第一个let和return之间的所有内容:

checkArg (com:arg) s d ns 
  | com == "add-source " = do
      let s' = v ++ s
      lift $ saveLinks s'
      return (s', d)
  | com == "remove-source" = do
      let s' = filter (not . hasWord str) s
      lift $ saveLinks s'
      return (s', d)

http://en.wikipedia.org/wiki/Off-side_rule


Tags: 函数标记comsource内容returnhaskell语法
2条回答

链接到的插件Jeet看起来很整洁,但是这里有一个简单的替代方法。在

如果你已经set foldmethod=indent。。。在

可以使用可视块选择。在

所以从第3行开始,只需输入V]z。在

:help fold-commands

MOVING OVER FOLDS

[z

Move to the start of the current open fold. If already at the start, move to the start of the fold that contains it. If there is no containing fold, the command fails. When a count is used, repeats the command [count] times.

]z

Move to the end of the current open fold. If already at the end, move to the end of the fold that contains it. If there is no containing fold, the command fails. When a count is used, repeats the command [count] times.

zj

Move downwards to the start of the next fold. A closed fold is counted as one fold. When a count is used, repeats the command [count] times. This command can be used after an operator.

zk

Move upwards to the end of the previous fold. A closed fold is counted as one fold. When a count is used, repeats the command [count] times. This command can be used after an operator.

我使用indent object plugin

This plugin defines a new text object, based on indentation levels. This is very useful in languages such as Python, in which the syntax defines scope in terms of indentation. Using the objects defined in this plugin, an entire if structure can be quickly selected, for example.

这样,您可以使用标准的Vim文本对象命令选择、删除、更改等块,使用“i”和“a”来表示您所在的块:“vii”、“dii”等。 它与语言无关,但在诸如Python这样的空白结构化语言中特别有用/相关。在

相关问题 更多 >