代码之家  ›  专栏  ›  技术社区  ›  advait

为什么Y和yy做同样的事?

vim
  •  9
  • advait  · 技术社区  · 14 年前

    我已经使用vim好几个月了,我已经习惯了使用C和D来更改和删除从光标到行尾的所有内容。

    foo.bar("hello world")
    

    foo.
    

    当点击C时,将在句点后对光标执行相同的加开始插入模式。

    但是,按Y键并不能做直观上相似的事情(从光标复制到行尾)。相反,它复制了整个行(就像yy一样)。

    如何使Y将字符从光标复制到行尾,而不是像yy那样复制整行?

    2 回复  |  直到 14 年前
        1
  •  5
  •   Jamie Wong    14 年前

    nmap Y y$

    编辑

    Y和yy做同样事情的原因可能与此有关:

    {Visual}["x]y           Yank the highlighted text [into register x] (for
                            {Visual} see |Visual-mode|).  {not in Vi}
    
                                                            *v_Y*
    {Visual}["x]Y           Yank the highlighted lines [into register x] (for
                            {Visual} see |Visual-mode|).  {not in Vi}
    

    Y是指行,Y是指单个字符?

        2
  •  9
  •   Brian Agnew    14 年前

    this configuration :

    " make Y effect to end of line instead of whole line
    map Y y$
    

    我怀疑违约行为仅仅是由于一些历史的不一致。