你能在 vi/vim 的括号之间抓取或删除吗? [英] Can you grab or delete between parentheses in vi/vim?

查看:28
本文介绍了你能在 vi/vim 的括号之间抓取或删除吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定这行 C 代码:

printf("%3.0f %6.1f ", fahr, ((5.0/9.0) * (fahr-32)));

printf("%3.0f %6.1f ", fahr, ((5.0/9.0) * (fahr-32)));

有没有办法从第一个粗括号删除或猛拉到匹配的括号?我想过 df),但这只会让你在 9.0 之后.

Is there a way to delete or yank from the first bold parenthesis to its matching parenthesis? I thought about df), but that only will get you to just after the 9.0.

有没有类似的方法让 vim 抓取匹配大括号之间的所有内容,而不管换行符如何?

Is there a similar way to get vim to grab everything between matching braces, regardless of newlines?

推荐答案

各种动作:%

% 命令 跳转到匹配光标下的项目.将光标定位在开始(或结束)括号上,并使用 y% 进行猛拉或使用 d% 删除从光标到匹配括号的所有内容.

Various Motions: %

The % command jumps to the match of the item under the cursor. Position the cursor on the opening (or closing) paren and use y% for yanking or d% for deleting everything from the cursor to the matching paren.

这是可行的,因为 % 是一个运动命令",所以它可以在 vim 需要这样命令的任何地方使用.来自 :help y:

This works because % is a "motion command", so it can be used anywhere vim expects such a command. From :help y:

["x]y{motion}       Yank {motion} text [into register x].  When no
                    characters are to be yanked (e.g., "y0" in column 1),
                    this is an error when 'cpoptions' includes the 'E'
                    flag.

默认情况下,item"包括括号、大括号、括号、C 风格的注释和各种预编译器语句(#ifdef 等).

By default, "item" includes brackets, braces, parens, C-style comments and various precompiler statements (#ifdef, etc.).

您可以在 上找到扩展%匹配"插件Vim 主页.

您可以通过输入 % 和相关运动命令的文档"noreferrer">:在命令模式下帮助各种动作.

You can read the documentation on % and related motion commands by entering :help various-motions in command mode.

您可以在可视模式下使用另一组运动命令来选择各种文本对象.

There is another set of motion commands that you can use in Visual mode to select various text objects.

要解决您的具体问题,您可以执行以下操作:

To solve your specific problem you would do the following:

printf("%3.0f	%6.1f
", fahr, ((5.0/9.0) * (fahr-32)));
                                   ^

假设您的光标位于 ^.输入以下序列以选择您要查找的部分:

Let's say your cursor is positioned at ^. Enter the following sequence to select the part you are looking for:

v2a)

首先 v 进入可视化模式,然后您指定要向上 2 级括号.最后 a) 选择一个块".之后就可以使用dx删除等

First v enters Visual mode, then you specify that you want to go 2 levels of parens up. Finally the a) selects "a block". After that you can use d or x to delete, etc.

如果不想包含外括号,可以使用内块"代替:

If you don't want to include the outer parens, you can use "inner block" instead:

v2i)

参见:help object-select 获取相关命令的完整列表.

See :help object-select for the complete list of related commands.

这篇关于你能在 vi/vim 的括号之间抓取或删除吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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