Vim中的x命令如何处理在可视模式下选择的文本,即使它不是运算符?

时间:2014-04-14 05:22:16

标签: vim

引用:h operator中提到的运算符列表:

The motion commands can be used after an operator command, to have the command
operate on the text that was moved over.  That is the text between the cursor
position before and after the motion.  Operators are generally used to delete
or change text.  The following operators are available:

    |c| c   change
    |d| d   delete
    |y| y   yank into register (does not change the text)
    |~| ~   swap case (only if 'tildeop' is set)
    |g~|    g~  swap case
    |gu|    gu  make lowercase
    |gU|    gU  make uppercase
    |!| !   filter through an external program
    |=| =   filter through 'equalprg' or C-indenting if empty
    |gq|    gq  text formatting
    |g?|    g?  ROT13 encoding
    |>| >   shift right
    |<| <   shift left
    |zf|    zf  define a fold
    |g@|    g@      call function set with the 'operatorfunc' option

引用视觉模式如何与:h operator的运算符一起使用:

Instead of first giving the operator and then a motion you can use Visual
mode: mark the start of the text with "v", move the cursor to the end of the
text that is to be affected and then hit the operator.  The text between the
start and the cursor position is highlighted, so you can see what text will
be operated upon.  This allows much more freedom, but requires more key
strokes and has limited redo functionality.

所以我理解,如果我在可视模式中选择几个单词并按 d ,则会删除所选单词,因为d运算符可以通过运动键指定其操作数或者以视觉模式选择文字。

但是我看到如果我在视觉模式中选择几个单词并按 x ,那么也会删除所选单词。但是x不是运营商。我无法理解Vim的帮助,而这应该有效。

请您帮助我了解哪些命令适用于以可视模式选择的文本,哪些命令不适用以及我如何从Vim的帮助中解决这个问题?

2 个答案:

答案 0 :(得分:4)

首先,d:d[elete]删除,他们剪切。对d使用 delete 这个词是一个严重的错误,它在Vim的文档中重复出现,几乎在网上到处都是。让d和朋友实际删除的唯一方法是使用&#34; blackhole&#34;注册,:help "_

其次,您可以通过从引用的:help向下滚动一点来找到问题的答案:

Additionally the following commands can be used:
    :   start Ex command for highlighted lines (1)  |v_:|
    r   change (4)                                  |v_r|
    s   change                                      |v_s|
    C   change (2)(4)                               |v_C|
    S   change (2)                                  |v_S|
    R   change (2)                                  |v_R|
    x   delete                                      |v_x|
    […]

并阅读:h x,再次向下滚动一下,或者更简单地说,按照行尾的v_x标记向下滚动。

你的问题写得很好并且布局合理,但你应该更加明智地花费你的时间和精力。例如,阅读第一个屏幕。

答案 1 :(得分:2)

您是正确的操作员命令通常会以可视模式进行运动更改,使您不指定运动,而是让命令对所选文本进行操作。但这只是一组在可视模式下工作的命令。

另一个组包含在当前/ [count]字符或行上工作(没有动作)的普通模式命令,如xr或{ {1}}。在可视模式下,这些也适用于所选文本。

这会在视觉模式中产生一些重叠,例如Jd都做同样的事情,而在正常模式下,xd5l会有所不同。