I have a file which looks like this:
1 148 1 4
2 333 1 3
3 534 2 3
4 772 g 7
5 921 p 2
I want to yank text from line 1 to 5 and from column 1 to 7:
1 148 1
2 333 1
3 534 2
4 772 g
5 921 p
can I do that from the vim command-line? If I type
:1,5ya a
the entire line is yanked into register "a" and I want just certain columns.
Thanks.
You can execute any command on the command line, here with the help of :normal
:
:execute "normal! 1G^\<C-v>6l5j\"ay"
This builds a blockwise selection, then yanks it to register a. The :execute
is used so that the \<C-v>
notation can be used instead of literally inserting it. It also allows you to replace the hard-coded limits with variables.
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