Vim select text

I have a file that 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 wrest text from row 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 this from the vim command line? If i print

:1,5ya a

the whole row is case-a-bound, and I only need certain columns.

Thank.

+5
source share
5 answers

You can execute any command on the command line, here with :normal:

:execute "normal! 1G^\<C-v>6l5j\"ay"

This creates a block selection and then registers it for registration a. :executeused so that instead of literally pasting it, you can use notation \<C-v>. It also allows you to replace hard-coded constraints with variables.

+2
source

vim. :y - linewise - ​​ . , , . . :

  • CTRL-V, .
  • , .
  • "ay, a.
+1

, :

:1,5y|put|-4,.s/\(.\{7\}\).*/\1/|-4,.d a

Yank 5 , () , , .

0

, script:

:let @a = join(map(getline(1, 5), 'matchstr(v:val, ".*\\%<9v")'), "\n")

(getline()), 7 /\%<v join() ed ) @a.

0

C-v G 2w y

( G G)

, a, "a:

C-v G 2w " a y

0
source

All Articles