如何在 Vim 中的括号(或引号或...)之间进行选择?

发布于 2024-07-26 07:50:00 字数 276 浏览 8 评论 0原文

我确信曾经有一个用于此类东西的插件,但现在我需要它,我似乎无法找到它(自然),所以我只会问一个简单的问题。

在括号、引号或匹配字符列表之间进行选择的最简单方法是什么?

   write ( *, '(a)' ) 'Computed solution coefficients:'

例如,在这里我想选择(a),或计算解系数:

我对多行不感兴趣,只对发生在一行上的情况感兴趣。

I'm sure there used to be a plugin for this kinda stuff, but now that I need it, I can't seem to find it (naturally), so I'll just ask nice and simple.

What is the easiest way to select between brackets, or quotes, or generally a list of matching characters?

   write ( *, '(a)' ) 'Computed solution coefficients:'

For example, here I'd like to select (a), or Computed solution coefficients:.

I'm not interested in multiline, just cases which occur on one line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

走走停停 2024-08-02 07:50:00

要在单引号之间进行选择,我通常执行 vi' (“选择内部单引号”)。

在括号块内,我使用 vib (“选择内部块”)

在花括号块内,您可以使用 viB (“大写 B”)

来使选择“包含” "(同时选择引号、圆括号或大括号)您可以使用 a 而不是 i

您可以阅读手册上有关文本对象选择的更多信息,或者< vim 中的 code>:help text-objects。

To select between the single quotes I usually do a vi' ("select inner single quotes").

Inside a parenthesis block, I use vib ("select inner block")

Inside a curly braces block you can use viB ("capital B")

To make the selections "inclusive" (select also the quotes, parenthesis or braces) you can use a instead of i.

You can read more about the Text object selections on the manual, or :help text-objects within vim.

阳光①夏 2024-08-02 07:50:00

使用您想要进入括号内的任何导航键,然后您可以使用 yi(yi) 复制匹配括号内的所有内容。 这也适用于方括号(例如yi])和花括号。 除了y之外,您还可以删除或更改文本(例如ci)di])。

我用双引号和单引号尝试过,它似乎也适用。 对于您的数据,我这样做:

write (*, '(a)') 'Computed solution coefficients:'

将光标移至 C,然后输入 yi'。 将光标移动到空行,点击 p,然后获取

Computed solution coefficients:

As CMS 已注明,这也适用于视觉模式选择 - 只需使用 vi)vi}vi' 等。

Use whatever navigation key you want to get inside the parentheses, then you can use either yi( or yi) to copy everything within the matching parens. This also works with square brackets (e.g. yi]) and curly braces. In addition to y, you can also delete or change text (e.g. ci), di]).

I tried this with double and single-quotes and it appears to work there as well. For your data, I do:

write (*, '(a)') 'Computed solution coefficients:'

Move cursor to the C, then type yi'. Move the cursor to a blank line, hit p, and get

Computed solution coefficients:

As CMS noted, this works for visual mode selection as well - just use vi), vi}, vi', etc.

南风几经秋 2024-08-02 07:50:00

这种选择方法是内置的,并在 Vim 帮助中详细介绍。 它涵盖了 XML 标签等。

请参阅:帮助文本对象

This method of selection is built-in and well covered in the Vim help. It covers XML tags and more.

See :help text-objects.

素衣风尘叹 2024-08-02 07:50:00

要在单引号内进行选择,请使用 vi'

要在括号内进行选择,请使用 vi(.

For selecting within single quotes use vi'.

For selecting within parenthesis use vi(.

你是年少的欢喜 2024-08-02 07:50:00

使用箭头或 hjkl 到达括号表达式之一,然后使用 v 选择视觉(即选择)模式,然后使用 % 跳转到另一个支架。

Use arrows or hjkl to get to one of the bracketing expressions, then v to select visual (i.e. selecting) mode, then % to jump to the other bracket.

三生路 2024-08-02 07:50:00

停在括号开头,然后全选并打印:

vi' 

vi(

vi[ 

vi{

vi<

vi"

如果要删除,请将 vi 替换为 di

Stop at the beginning of brackets, and then select all and print:

vi' 

vi(

vi[ 

vi{

vi<

vi"

if you want to delete replace vi with di

岁月如刀 2024-08-02 07:50:00

我想对已经很好的答案进行补充。 我来这里寻找一种方法来更改 html 括号内的文本,所以我想为其他也在寻找该方法的人提供答案。

您可能认为 ci< 会起作用,但实际上只有当您位于其中一个标签本身时才有效:

<would work inside here> But not here </would work inside here>

我想要的是更改 html 标签本身之间的文本:

<div>change me</div>

我想要的是“更改inside tag": cit

感谢您提到文档(:help text-objects)的其他答案,这就是我找到我正在寻找的内容的方式。

I wanted to add to the already good answers. I came here looking for a way to change the text inside of html brackets, so I want to provide an answer for anyone else that is also looking for that.

You might think ci< would work, but actually that only works if you are inside one of the tags themselves:

<would work inside here> But not here </would work inside here>

What I wanted was to change the text between the html tags themselves:

<div>change me</div>

What I wanted was "change inner tag": cit

Thank you to the other answer that mentioned the documentation (:help text-objects) which is how I found what I was looking for.

屋顶上的小猫咪 2024-08-02 07:50:00

使用 searchpair 内置函数在 .vimrc 中编写 Vim 函数:

searchpair({start}, {middle}, {end} [, {flags} [, {skip}
            [, {stopline} [, {timeout}]]]])
    Search for the match of a nested start-end pair.  This can be
    used to find the "endif" that matches an "if", while other
    if/endif pairs in between are ignored.
    [...]

(http://vimdoc.sourceforge.net/htmldoc/eval.html

Write a Vim function in .vimrc using the searchpair built-in function:

searchpair({start}, {middle}, {end} [, {flags} [, {skip}
            [, {stopline} [, {timeout}]]]])
    Search for the match of a nested start-end pair.  This can be
    used to find the "endif" that matches an "if", while other
    if/endif pairs in between are ignored.
    [...]

(http://vimdoc.sourceforge.net/htmldoc/eval.html)

‖放下 2024-08-02 07:50:00

我会在投票最多的答案中添加一个细节:

如果您使用 gvim 并想要复制到剪贴板,请使用

"+

复制括号(或括号或大括号)

例如: "+yi} 会将光标所在大括号之间的所有内容复制到剪贴板。

I would add a detail to the most voted answer:

If you're using gvim and want to copy to the clipboard, use

"+<command>

To copy all the content between brackets (or parens or curly brackets)

For example: "+yi} will copy to the clipboard all the content between the curly brackets your cursor is.

落墨 2024-08-02 07:50:00

我制作了一个插件 vim-textobj-quoteshttps:// github.com/beloglazov/vim-textobj-quotes

它为任何类型的最接近的引号对提供文本对象。 仅使用 iqaq 即可对当前光标周围的单引号 (')、双引号 (") 或反引号 (`) 的内容进行操作,位于光标前面或后面(按照优先顺序),当需要到达引号时,它会向前或向后跳转。

通过查看示例更容易理解(光标用 显示)。 |):

  1. 之前:foo '1, |2, 3' bar;按 diq 后:foo '|' bar
  2. 之前:foo| '1, 2, 3' bar;按 diq 后:foo '|' bar
  3. 之前:foo '1, 2, 3' |bar;按 diq 后:foo '|' bar
  4. 之前:foo '1, |2, 3' bar; 按 daq 后:foo | bar
  5. 之前:foo| '1, 2, 3' bar; 按 daq 后:foo | bar
  6. 之前:foo '1, 2, 3' |bar; 按 daq 后: foo | bar

上面的示例是针对单引号,该插件的工作方式与双引号 (") 和反 (`) 引号。

您还可以使用任何其他运算符:ciqdiqyiqviq 等。

请查看在上面链接的 github 页面上了解更多详细信息。

I've made a plugin vim-textobj-quotes: https://github.com/beloglazov/vim-textobj-quotes

It provides text objects for the closest pairs of quotes of any type. Using only iq or aq it allows you to operate on the content of single ('), double ("), or back (`) quotes that currently surround the cursor, are in front of the cursor, or behind (in that order of preference). In other words, it jumps forward or backwards when needed to reach the quotes.

It's easier to understand by looking at examples (the cursor is shown with |):

  1. Before: foo '1, |2, 3' bar; after pressing diq: foo '|' bar
  2. Before: foo| '1, 2, 3' bar; after pressing diq: foo '|' bar
  3. Before: foo '1, 2, 3' |bar; after pressing diq: foo '|' bar
  4. Before: foo '1, |2, 3' bar; after pressing daq: foo | bar
  5. Before: foo| '1, 2, 3' bar; after pressing daq: foo | bar
  6. Before: foo '1, 2, 3' |bar; after pressing daq: foo | bar

The examples above are given for single quotes, the plugin works exactly the same way for double (") and back (`) quotes.

You can also use any other operators: ciq, diq, yiq, viq, etc.

Please have a look at the github page linked above for more details.

极致的悲 2024-08-02 07:50:00

vim 中的一个简单的键盘映射可以解决这个问题。
地图 viq F”lvf”hh
上面的命令将 viq 映射到键以在引号之间进行搜索。 将 " 替换为任何字符并创建您的键盘映射。
在启动时将其粘贴到 vimrc 中,您应该每次都可以使用它。

A simple keymap in vim would solve this issue.
map viq F”lvf”hh
This above command maps viq to the keys to search between quotes. Replace " with any character and create your keymaps.
Stick this in vimrc during startup and you should be able to use it everytime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文