根据Vim中的缩进级别标记块 [英] Mark block based on indentation level in Vim

查看:117
本文介绍了根据Vim中的缩进级别标记块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据已有的缩进在Vim中标记块?类似于v {。

Is it possible to mark a block in Vim based on the indentation already in place? Similarly to v{ .

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

It would be extremely useful for programming languages with whitespace-sensitive syntax (like Haskell and Python).

例如,在这个函数中标记第一个let和return之间的所有东西:

For example mark everything between the first let and return in this function:

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

推荐答案

我使用缩进对象插件

I use the indent object plugin:


这个插件根据缩进级别定义了一个新的文本对象。
这对Python等语言非常有用,其中语法
根据缩进定义范围。使用
中定义的对象插件,可以快速选择整个if结构,例如

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等空白结构化语言中特别有用/相关。

With this, you can select, delete, change, etc. blocks using the standard Vim text object commands, using "i" and "a" to refer to the block that you are in: "vii", "dii", etc. It it language-agnostic, though is especially useful/relevant in whitespace-structured languages such as Python.

这篇关于根据Vim中的缩进级别标记块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆