25

im trying to copy 300 lines from one file to another, in source file i type "300yy", it says it has yanked 300 lines.

go to destination file and press p, it pastes, but only the first 50 lines.

any idea why it isn't pasting the 300?

john-jones
  • 7,490
  • 18
  • 53
  • 86
  • 1
    Does `echo @"` echo all your lines? How do you go to destination file (in this vim instance, or in other)? If you want to save this 300 lines across vim sessions, then you need to modify your viminfo variable as suggested by @eugene y (though you should just remove `,<100` and `,s10` parts of the string). In my vim moving 2800 lines in one vim session works just fine. – ZyX Sep 09 '10 at 13:37
  • And please paste your version info. – ZyX Sep 09 '10 at 13:43
  • 1
    im on vim 7.2, removing the ,<100 and ,s10 did the trick. – john-jones Sep 09 '10 at 14:12

5 Answers5

37

To see the current settings during a vim session, run:

:set viminfo?

As suggested in Vim Tips Wiki, you can adjust the viminfo setting (again, during a vim session) by running the ex-command:

:set viminfo='100,<1000,s100,h

or you can remove the : and set it as default in your .vimrc as:

set viminfo='100,<1000,s100,h

What the individual parts mean:

  • '100 Marks will be remembered for the last 100 edited files.
  • <1000 Limits the number of lines saved for each register to 1000 lines; if a register contains more than 1000 lines, only the first 1000 lines are saved.
  • s100 Registers with more than 100 KB of text are skipped.
  • h Disables search highlighting when Vim starts.
Louis Maddox
  • 5,226
  • 5
  • 36
  • 66
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
  • 1
    do you know what each one of those '100,<100,s10,h lines mean? – john-jones Sep 09 '10 at 14:00
  • this is a vastly superior documentation of the solution to those problems. – john-jones Sep 09 '10 at 14:46
  • 3
    Just a quick note that ":help viminfo" and ":help 'viminfo'" pull up different helps. The latter is the one that you need. – Jeet Sep 09 '10 at 15:24
  • What does this set the limit to? – franka Jan 14 '14 at 20:48
  • 1
    @franka As stated in the :help 'viminfo', < indicates the "Maximum number of lines saved for each register." The default is 50 and in the answer above it is increased to 100. – Peter Thorpe Jul 11 '14 at 07:52
  • Viminfo gives you the following <\n> :set viminfo='50,<1000,s100,:0,n~/vim/viminfo < '50 Marks will be remembered for the last 50 files you edited. <1000 Contents of registers (up to 1000 lines each) will be remembered. s100 Registers with more than 100 Kbyte text are skipped. :0 Command-line history will not be saved. – Raghav Oct 20 '14 at 17:55
  • when I use `set set viminfo='100,<1000,s100,h` in my `vimrc`, everytime I startup vim, it shows me the setting `viminfo='100,<1000,s100,h` and asks me to press enter. Is there a reason why? – alpha_989 May 27 '18 at 23:01
  • @alpha_989 the first command was displaying the current setting, which was running every time you started vim. I've edited the answer to be clearer about how you can supply this as a setting (it was copied directly from the VimTips wiki). I've gone with `s200` rather than `s100` – Louis Maddox Apr 22 '21 at 11:42
9

As Eugene and Zyx said adjusting your viminfo would be the easiest solution

:set viminfo-=<50,s10

An alternate solution would be use :read and/or :write

To read in from file-name.txt into the current buffer

:read file-name.txt

To append the range of line 1 to line 300 from the current buffer to file-to-append.txt

:1,300write >> file-to-append.txt

You can also use marks instead of line numbers such as the visual marks

:'<,'>write >> file-to-append.txt

Of course appending may not be able to fulfill your use case in which the viminfo changes will probably work best.

:help :write
:help :read
:help 'viminfo'
:help :set-=
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
  • before switching from vi to vim I set the following abbrevation (don't remember why I used ab instead of map) : `cab wbf w! ~/.lastbuffer` and `rbf r ~/.lastbuffer` which respectively write and read always the same file. Then just do `:wbf` and `:rbf` – mb14 Sep 09 '10 at 16:09
  • @Peter, wondering why it is important to take `<50,s10` out of viminfo.. rather than just setting viminfo with `set viminfo='100,<1000,s100,h`? – alpha_989 May 27 '18 at 22:58
  • Just depends on what each person wants set. Nothing wrong with setting it fully. That being said if more options are added in the future it could be a bit trickier – Peter Rincker May 27 '18 at 23:27
5

Stay in the same session (open the new file doing :e path) and you won't have any limitation.

mb14
  • 22,276
  • 7
  • 60
  • 102
4

try vim -p file1 file2. It opens each file into a new tab (which is awesome), and it solves the copy/paste limit

d-_-b
  • 21,536
  • 40
  • 150
  • 256
0

Something that worked for me is, when in visual mode, copying with a command like :1,300y that copies from line 1 to 300. You can switch this to any range of lines that you would like as :37,456y to copy from line 37 to 456.

If your vim is not showing the lines, you can set the lines with the command :set numbers

If you want to use that yanked/copied lines in another file, i recommend opening multiples tabs and copying and pasting the info between them. To do this you can open them in the terminal with the command vim -p file1 file2. To navigete between them you can use the commands gt and gT to move to the next and previous tab respectively.