Is there a way in vim to read a file, like with :r
, and then store it in some register? and is there a way to do the same, but only with the lines in the file that matches some pattern?
Try this:
:let @x = join(readfile("~/.vimrc"), "\n")
It will read .vimrc
to register x
.
Using external grep, you could do:
:let @x = system('grep pattern filename')
to place only the lines matching pattern
from file filename
in register x
.
You can create a new buffer with :new
, read the file :r <filename>
, yank the entire file for a register (say, x) with gg"xyG"
, and delete the buffer with :q!
.
If you intend to perform this actions several times you can create a mapping for it.
To do the same with lines that matches a pattern, you can peform a global command (:h :g
) before performing the copy to the register.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With