在 VI/M ex 命令中标记一个字符块

发布于 2024-12-27 10:05:43 字数 1797 浏览 4 评论 0原文

对于 VI/M 来说,标记从第 M 行到第 N 行的行块准备删除、剪切和删除是相当简单的。过去,或复制&粘贴。

:M,N d
:M,N m p
:M,N t p 

如果还需要VI/M标记从第M行第I个字符到第N行第J个字符的字符块,是否可以实现与上面类似的功能?

@EDIT

除了下一个要求视觉块模式的答案之外,输入简洁的 ex 命令的选项怎么样?

@EDIT 2

澄清字符块的含义:

  • 方形块字符,通过视觉块模式,通过在正常模式下按Ctrl-v直接调用
  • 连续字符的zipzag区域,寻址通过视觉字符模式,直接调用在正常模式下按v
  • ,连续行的行区域,由可视行模式寻址,直接调用在正常模式下按V即可。在这种情况下,上面最初提出这个主题时已经说明了 ex 模式 中的便捷解决方案。

@SOLUTION

ex 模式 中选择从 M 行、I 列到 N 行、J 列的连续字符的任意 zipzag 区域,与 中完全相同>视觉字符模式 :

标记:

:normal! MggI|vNggJ|

删除:

:normal! MggI|vNggJ|d

复制:

:normal! MggI|vNggJ|y

移动到 X 行 Y 列

:normal! MggI|vNggJ|dXggY|p

复制到 X 行 Y 列

:normal! MggI|vNggJ|yXggY|p

@SOLUTION 2

选择任意方块字符从 M 行,列在 ex 模式 中,I 到第 N 行,第 J 列,与在 视觉块模式 中完全相同:

标记:

:execute "normal! MggI|\<C-v>NggJ|"

删除:

:execute "normal! MggI|\<C-v>NggJ|d"

复制:

:execute "normal! MggI|\<C-v>NggJ|y"

移动到 X 行 Y 列

:execute "normal! MggI|\<C-v>NggJ|dXggY|p"

复制到 X 行 Y 列

:execute "normal! MggI|\<C-v>NggJ|yXggY|p"

It's quite straitforward for VI/M to mark a block of lines from Mth line to Nth line ready to delete, cut & past, or copy & paste.

:M,N d
:M,N m p
:M,N t p 

If it's further required for VI/M to mark a block of characters from Ith character of Mth line to Jth character of Nth line, is it possible to accomplish similarly to the above?

@EDIT

Except the next answer asked for visual block mode, how about the option on typing a succinct ex command?

@EDIT 2

To clarify the meaning of a block of characters:

  • a square block of characters, addressed by visual block mode, directly called upon by pressing Ctrl-v in normal mode
  • a zipzag area of successive characters, addressed by visual character mode, directly called upon by pressing v in normal mode
  • a rows region of successive lines, addressed by visual line mode, directly called upon by pressing V in normal mode. In this case, the handy solution in ex mode has been illustrated above when this topic was originally raised.

@SOLUTION

Selecting abitrary zipzag area of successive characters from line M, column I to line N, column J in ex mode exactly like in visual character mode :

mark:

:normal! MggI|vNggJ|

delete:

:normal! MggI|vNggJ|d

yank:

:normal! MggI|vNggJ|y

move to line X column Y

:normal! MggI|vNggJ|dXggY|p

copy to line X column Y

:normal! MggI|vNggJ|yXggY|p

@SOLUTION 2

Selecting abitrary square block of characters from line M, column I to line N, column J in ex mode exactly like in visual block mode :

mark:

:execute "normal! MggI|\<C-v>NggJ|"

delete:

:execute "normal! MggI|\<C-v>NggJ|d"

yank:

:execute "normal! MggI|\<C-v>NggJ|y"

move to line X column Y

:execute "normal! MggI|\<C-v>NggJ|dXggY|p"

copy to line X column Y

:execute "normal! MggI|\<C-v>NggJ|yXggY|p"

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

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

发布评论

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

评论(2

美煞众生 2025-01-03 10:05:43

您可以使用 normal! 从 ex 命令模式使用可视块模式:例如,从 (42, 10) 到 (54, 20) 选择一个块(行、列)并将其拉出 (两行必须至少有 20 个字符,否则应设置 virtualedit=block):

execute "normal! 42gg10|\<C-v>54gg20|y"

。这是非常简单的方法,仅在脚本中有用。

请注意,此命令至少有以下副作用:

  1. 设置标记 '<'>'[' ]''
  2. 移动光标。
  3. 更改寄存器 @"@0
  4. 将一项添加到跳转列表。
  5. 覆盖之前的视觉选择。
  6. 更改 v:countv :count1 变量。

You can use visual block mode from an ex command mode using normal!: for example, to select a block (line, column) from (42, 10) to (54, 20) and yank it (both lines must have at least 20 characters or virtualedit=block should be set):

execute "normal! 42gg10|\<C-v>54gg20|y"

. It is very straightforward way to do this, useful only in scripts.

Note that this command has at least following side-effects:

  1. Setting marks '<, '>, '[, '], ''.
  2. Moving a cursor.
  3. Changing registers @", @0.
  4. Adding one item to the jumplist.
  5. Overwriting previous visual selection.
  6. Altering v:count and v:count1 variables.
缱倦旧时光 2025-01-03 10:05:43

Ctrl+V 启用可视块模式,然后您可以使用箭头键选择块。

Ctrl+V enables visual block mode, then you can use the arrow keys to select the block.

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