如何从 Vim 中的括号外快速选择带括号的文本? [英] How to quickly select parenthesized text from outside of the parentheses in Vim?

查看:51
本文介绍了如何从 Vim 中的括号外快速选择带括号的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过在普通模式下输入 vi'vi" 来选择单引号或双引号内的文本.例如,光标位于此处的字母 H 处:

I know that I can select the text inside single or double quotes by typing vi' or vi" in Normal mode. For example, with the cursor located at the letter H here:

Hello "World"

我可以通过发出 vi" 来选择单词 World.

I can select the word World by issuing vi".

但是如果 World 被括号而不是被引用,这似乎不起作用:

But this does not seem to work if World is parenthesized instead of being quoted:

Hello (World)

如果我的光标位于 H 并且我尝试使用 vi) 选择 World,它不起作用.似乎唯一的方法是首先将光标实际移动到括号内,然后才发出 vi).

If my cursor is at H and I try to select World using vi), it does not work. It seems that the only way to do this is to actually move your cursor inside the parentheses first and only then issue vi).

为什么选择括号和引号内的文本会有这种不同?

Why does selecting text inside parentheses and quotes differ in this way?

推荐答案

{a,i}×{(,),b} 文本对象命令以及它们的 "'` 对应项主要来自带引号的字符串定义的区别(参见:help v_ab:help v_aquote).

The difference between {a,i}×{(,),b} text-object commands and their ", ', ` counterparts primarily results from the difference in definitions of a block and a quoted string (see :help v_ab, :help v_aquote).

虽然后者是来自前一个引号字符的文本当前行直到同一行上的下一个(转义的放在一边),前者是 n 个前一个不匹配开头之间的文本括号和匹配的结束之一.简单地说,命令va( (没有计数) 就像 [(v%—如果没有不匹配的光标前的括号,都没有选择.然而,命令 va" 扫描当前行以找到匹配对无论如何.

While the latter is the text from the previous quote character on the current line until the next one on that same line (escaped ones aside), the former is the text between the nth previous unmatched opening parenthesis and the matching closing one. Simply put, the command va( (without a count) is like [(v%—if there is no unmatched parenthesis before the cursor, both select nothing. However, the command va" scans the current line to find a matching pair of quotes, anyway.

我想这种行为差异的主要原因是与括号相反,带引号的字符串被假定为非嵌套(至少从内置 Vim 文本对象的角度来看).

The main reason for this difference in behavior, I suppose, is that quoted strings, in contrast to parenthesis, are assumed to be non-nested (at least in perspective of the built-in Vim text objects).

要选择当前行下一个括号中的文本,一个可以使用 %vi(%va(,具体取决于是否需要分别在选择中包含或不包含括号.

To select the text in the next parenthesis on the current line, one can use %vi( or %va(, depending on whether it is desirable to include the parentheses in the selection or not, respectively.

这篇关于如何从 Vim 中的括号外快速选择带括号的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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