Vim对象选择和支持语法的文本对象 [英] Vim object-select with syntax-aware text-objects

查看:119
本文介绍了Vim对象选择和支持语法的文本对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚了解了真正令人敬畏的

I just learned about the truly awesome object-select capabilities of vim. With the cursor within some "text object", a set of simple verbs can select or operate on the whole object. For example, with the cursor anywhere inside the quotes below (e.g. over the 'o'):

print "Hello, world"
           ^

命令vi"将选择引号内的整个短语.相同的功能适用于vim的许多"文本对象"定义(包括用引号,括号和大括号括起来的单词,句子,段落和字符).

The command vi" will select the whole phrase inside the quotes. The same capability works with a number of "text objects" that vim defines, including words, sentences, paragraphs, and characters enclosed by quotes, parentheses, and braces.

但是现在我希望文本对象"的这种概念了解我正在编写的语言.例如,考虑以下python:

But now I want this notion of a "text object" to be aware of the language I'm writing. For example, consider the following python:

re.sub("[^A-Z ]", " ", string)

我希望能够将光标放置在其上方的某处,并选择整个对象.函数调用是定义明确的语法构造,但不是单词",句子",段落"或用引号或花括号引起的.

I'd like to be able to place the cursor somewhere over that, and to select the whole thing. The function call is a well-defined syntactic construct, but it isn't a "word", "sentence", "paragraph", or enclosed in quotes or braces.

有没有定义这些依赖于语言的文本对象"的插件或vimrc hack?

Are there any plugins or vimrc hacks out there that define these sorts of language-dependent "text objects"?

推荐答案

此脚本使用缩进定义文本对象.如果您按照通用标准进行格式化,并且适用于python,那么它将适用于多种语言.

This script uses indentation to define a text-object. It'll work for many languages if you're formatting according to common standards, and guaranteed for python.

这篇关于Vim对象选择和支持语法的文本对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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