首页 > 解决方案 > 如何向可视块中的所有行发出命令?

问题描述

如何在逐行可视块中的所有行上执行类似dtR(删除直到遇到R行中的)之类的操作,或者说,对于下一n行?

漫长的故事

假设有以下代码:

L0 = Rotated_Shape((1, 0), (-1, 0), (-1, 1))
L90 = Rotated_Shape((0, -1), (0, 1), (1, 1))
L180 = Rotated_Shape((-1, 0), (1, 0), (1, -1))
L270 = Rotated_Shape((0, 1), (0, -1), (-1, -1))

O0 = Rotated_Shape((1, 0), (1, -1), (0, -1))
O90 = Rotated_Shape((0, -1), (-1, -1), (-1, 0))
O180 = Rotated_Shape((-1, 0), (-1, 1), (0, 1))
O270 = Rotated_Shape((0, 1), (1, 1), (1, 0))

S0 = Rotated_Shape((-1, 0), (0, -1), (1, -1))
S90 = Rotated_Shape((0, 1), (-1, 0), (-1, -1))
S180 = Rotated_Shape((1, 0), (0, 1), (-1, 1))
S270 = Rotated_Shape((0, -1), (1, 0), (1, 1))

T0 = Rotated_Shape((0, 1), (-1, 0), (1, 0))
T90 = Rotated_Shape((1, 0), (0, 1), (0, -1))
T180 = Rotated_Shape((0, -1), (1, 0), (-1, 0))
T270 = Rotated_Shape((-1, 0), (0, -1), (0, 1))

Z0 = Rotated_Shape((1, 0), (0, -1), (-1, -1))
Z90 = Rotated_Shape((0, -1), (-1, 0), (-1, 1))
Z180 = Rotated_Shape((-1, 0), (0, 1), (1, 1))
Z270 = Rotated_Shape((0, 1), (1, 0), (1, -1))

我现在正在修改这段代码,我希望所有这些行都成为等式(赋值)右侧的内容,即删除变量名、等号并只保留Rotated_Shape((...部分。

我想完成这种特殊情况的最佳方法是搜索和替换正则表达式,但我不知道该怎么做的第一种方法是对它们中的每一个使用块可视化或线可视化模式并执行类似的东西dtR(删除,直到你遇到R行中的)。

标签: vim

解决方案


您可以使用视觉块突出显示这些行,然后使用:help 'normal'.

选择后的最终结果如下所示::'<,'>normal dtR

您也可以缩写normalnorm.


推荐阅读