1

I trying to search and copy the matches within a limited scope in vim. as mentioned in this answer. I am trying to copy the result into a new vim tab using

:'<,'>g/foo/y A

but when a open a new tab :tabnew and try to paste p nothing is showing.
1. so, my question is if i can redirect the gsearch output into a new tab?
2. or how do i properly copy the output into a register and paste from the register to a new tab?

isnvi23h4
  • 1,910
  • 1
  • 27
  • 45

1 Answers1

3

Solution for option 1:

Redirecting matched text to new tab

  :tabnew | :normal! i^R/

To put ^R, you have to press Ctrl and V, and then R.

The above command pastes the contents of search register, which is foo in your case. If you wanted to put the content of any other register, you can put that character instead of slash.

  :tabnew | :normal! i^Ra

This will paste the contents of register a, in which you have saved the output of global search command.

Solution for option 2: properly copy and paste through register

Your command works perfectly! It copies the output of global search to register a. So, you can directly open another tab by :tabnew and then press "ap to paste it, or go to insert mode by pressing i and then press Ctrl and R, and then a. The contents of register a is pasted there.

Community
  • 1
  • 1
SibiCoder
  • 1,396
  • 10
  • 21
  • 1
    i think i was missing out the "Ap in the new tap instead i was using only p. when i copy to the register A, does it append to the previous copy, or does it clears the old copies and only holds the fresh copy? – isnvi23h4 Jul 15 '16 at 10:59
  • When you give capital letter, it appends the content to the same register. When you try to paste by p, it pastes the recently deleted/copied text. You can see the contents of registers by typing `:registers` in command line mode. When you copy something to a register using small letter, its older content is erased. – SibiCoder Jul 15 '16 at 11:05