-1

When I copy lines with vim on my ssh term I always have the line number:

 1 <?php
 2 echo "test";
 3

I try many things like:

set mouse=a
set mousehide
set pastetoggle=

I enter into visual mode it's doesn't highlight line numbers but I can't copy.

I don't want to unset number and set again each time I want to copy something ;)

Does a script exist? Like autocmd or something like that?

I'm on Mac Os X, but I use vim over ssh (-clipboard).

Note it's not a duplicate of: How to clear the line number in Vim when copying?

So it's a duplicate of: Scrolling inside Vim in Mac's Terminal

If moderator can (re)link please?

Community
  • 1
  • 1
ChoiZ
  • 747
  • 1
  • 5
  • 23
  • it's hard to understand what you're asking here...do you want to copy line numbers from vim, or are you having some issue where the line numbers are copied each time you select something in the terminal? – mihai Mar 12 '13 at 23:27
  • I'm guessing that what you're trying to do is copy a mouse selection to your system clipboard so that you can paste it elsewhere. How to do this varies depending on your OS and how your Vim was compiled, as well as how your Vim is configured. Here's one example SO question (mostly OSX-specific): http://stackoverflow.com/questions/677986/vim-copy-selection-to-os-x-clipboard. The exact configuration required depends on information beyond what you've provided. Search SO/Google for "vim selection clipboard" and you'll find plenty of solutions. – Jim Stewart Mar 12 '13 at 23:33
  • Are you working locally? Remotely? What OS do you use? – romainl Mar 13 '13 at 07:41
  • Thanks Jim Stewart maybe the correct answer is this one… http://stackoverflow.com/a/679419/913154 – ChoiZ Mar 13 '13 at 12:48
  • Now I have the ultimate solution for Mac Os: I use iTerm2, with xterm-256color. I use Vim with MacVim and in my vimrc: ```set mouse=a``` ```set clipboard+=unnamed``` Now I can copy and paste without line number. I select line 1 to 10 with mouse and I hint 'y' for copying or ```:1,10y``` And I can paste with command+v on my mac ;) – ChoiZ Feb 10 '14 at 12:35

2 Answers2

12

Don't use the mouse. Copy to the + register instead with

:1,3y+

which copies it to your system's clipboard. For this to work, your vim must have been compiled with the clipboard option (i.e., :version should have +clipboard in the options).

abcd
  • 41,765
  • 7
  • 81
  • 98
2

Most Vims can interact with the clipboard; just yank the text into register "+ (or "*), see :help quoteplus.

If you absolutely must copy directly from the terminal with the mouse, you have to temporarily :set nonumber.

You can write a mapping to speed that up:

:nnoremap <Leader>n :set invnumber number?<CR>
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 1
    I'm in my terminal on Mac Os X. Connected in Linux on SSH and i use vim remotelly. When i copy lines with my mouse i always select line numbers. With mouse=a i can select text only but i can't copy. – ChoiZ Mar 13 '13 at 12:27