Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim select text

Tags:

vim

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.

like image 275
armando Avatar asked Oct 22 '22 17:10

armando


1 Answers

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.

like image 61
Ingo Karkat Avatar answered Oct 25 '22 18:10

Ingo Karkat