当我使用vim的块选择尝试从行末删除时,出现了异常行为。
假设我有这样一段文本:
delete this char:x
and this:x
also this:x
and then this:x
lastly this:x
如果我想在每一行末尾添加
y
,可以按以下步骤进行操作:
- 使用C-v开始块选择
- 使用
4j
选择所有行 - 使用
$
移动到每行末尾 - 使用
A
开始追加 - 输入所需文本
y
delete this char:xy
and this:xy
also this:xy
and then this:xy
lastly this:xy
但是,如果我尝试在最后一步中删除x
而不是添加它,我希望得到以下结果:
delete this char:
and this:
also this:
and then this:
lastly this:
尽管我最终得到:
delete this char:
and this:x:
also this:x:
and then this:x:
lastly this:x:
据我所知,它会将第一行的最后一个字符附加到所有其他行(在这种情况下是
:
),而不是删除缺失的字符(在这种情况下是x
)。我可以使用宏或替换来完成此操作,但我不太理解这种行为背后的原理。是否有一种方法可以通过块选择来实现这个功能?
x
被移除,但没有添加任何内容。 - romainl<C-v>{movement}$A
,无论如何都不会在选择中的每一行上删除字符。只有添加字符有效。如果你想听我的意见,这有点短视,但这就是它的设计方式。通常使用:'<,'>norm $x
或:'<,'>s/x$//
来删除一系列行末的x
。 - romainl