Vim复制行号?

5

我正在通过SSH连接使用vim。我已经设置了数字,所以每当我尝试用鼠标复制我的代码部分时...它也会抓取数字。有没有一种好的方法可以复制文本而不带数字呢?(我知道在vim中可以使用Y,但我需要一种将其复制到其他实例和程序的方法)。

这是我所说的一个例子。

1 function foo ( home, ip, hash, regex )
2 {
3 return false;
4 }

非常感谢大家给予的建议。

你的 mouse 设置好了吗?:set mouse? 返回什么? - none
3个回答

9

使用 ! 切换 'number' 设置

:set nu!

运行一次可以关闭'number',再次运行该命令可以重新打开该设置。

我在我的~/.vimrc文件中使用以下映射:

nnoremap <leader>tn :set nu! nu?<cr>

这将切换该设置,然后输出'number'的当前值。

更多帮助请参见:

:h 'nu'
:h :set-!

我遇到的问题是,即使切换了此设置,由于某种原因,实际上复制效果变得更糟。缩进会累积,并且变得非常混乱。 - Eman

6
:set nonumber

复制你想要的内容

:set number

:帮助编号


那个方法可以,但我更倾向于找一个不需要转换数字的方式。 - Eman
我不知道那是否可能,也许其他人会有更好的建议。 - gpojd
好的,事实证明,因为我在终端中使用它,它会影响一些设置。这个问题与设置粘贴模式有关,但是现在已经解决了。谢谢。 - Eman

6
  • If you copy and paste within Vim, there is no valid reason to not use the proper commands: y to "yank" (copy, see :help y) and p to "put" (paste, see :help p).

  • If you copy in remote Vim to paste in another local app, you'll have to:

    :set nonumber
    do your thing
    :set number
    

    You might want to verify if you are able to use "X11 Forwarding" as it enables two-way clipboard sharing.

  • If you copy in a local app to paste in remote Vim, you'll have to:

    copy in local app
    go to Vim
    :set paste
    Ctrl+v or Cmd+v
    :set nopaste
    

    See :help pastetoggle for a handy mapping.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接