Eman
Eman

Reputation: 6721

Vim copying the line numbers?

I am using vim through and SSH connection. I have the numbers setting set, and so when ever I try to copy sections of my code with the mouse...it grabs the numbers also. Is there a good way to copy text that doesn't grab the numbers with it. (I know that with in that instance of vim I can use Y, but I need a way to copy to other instances and programs).

Here's an example of what I am talking about.

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

Thank you all very much for the advice.

Upvotes: 5

Views: 1876

Answers (3)

romainl
romainl

Reputation: 196886

  • 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.

Upvotes: 6

Peter Rincker
Peter Rincker

Reputation: 45177

Toggle the 'number' setting with a !

:set nu!

Run it once to turn off 'number'. Run the command again to turn the setting back on.

I use the following mapping in my ~/.vimrc:

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

It will toggle the setting and then echo out the current value of 'number'

For more help see:

:h 'nu'
:h :set-!

Upvotes: 9

gpojd
gpojd

Reputation: 23085

:set nonumber

copy what you want

:set number

:help number

Upvotes: 6

Related Questions