在 VI/M ex 命令中标记一个字符块
对于 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 innormal mode
- a zipzag area of successive characters, addressed by
visual character mode
, directly called upon by pressing v innormal mode
- a rows region of successive lines, addressed by
visual line mode
, directly called upon by pressing V innormal mode
. In this case, the handy solution inex 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
normal!
从 ex 命令模式使用可视块模式:例如,从 (42, 10) 到 (54, 20) 选择一个块(行、列)并将其拉出 (两行必须至少有 20 个字符,否则应设置virtualedit=block
):。这是非常简单的方法,仅在脚本中有用。
请注意,此命令至少有以下副作用:
'<
、'>
、'[
、' ]
,''
。@"
、@0
。v:count
和v :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 orvirtualedit=block
should be set):. It is very straightforward way to do this, useful only in scripts.
Note that this command has at least following side-effects:
'<
,'>
,'[
,']
,''
.@"
,@0
.v:count
andv:count1
variables.Ctrl+V 启用可视块模式,然后您可以使用箭头键选择块。
Ctrl+V enables visual block mode, then you can use the arrow keys to select the block.