How to copy entire file to clipboard together with line numbers in Vim

215 Views Asked by At

I enabled vim-gtk, opened a file, did :set nu, but the command :%y+ does not copy the line numbers to the clipboard.

That may be resolved in visual mode (I do not know how to use it), but sometimes files are very long and I guess it is impractical.

Also does :set nonumber have a shorter alias like :set number has :set nu?

2

There are 2 best solutions below

0
On

:set nonumber is the same as :set nonu.

Line numbers will not be copied. But, if you copy the entire file, just enable line numbers where you paste in.

0
On

To copy the entire file with line numbers to the "+ register (which is CLIPBOARD buffer under X11) you may use:

:redir @+ | silent %# | redir END