Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yanking by line number in vim

Tags:

vim

yank

I have a file and I want to do the following.

- copy every n lines starting from m (m,m+n,m+2n, ...)
- copy line number 2, 5, 27, ... by specifying line numbers.

THanks

like image 771
eli Avatar asked Feb 17 '23 00:02

eli


1 Answers

To copy every N lines, you can use :global with an expression that selects the lines:

:let @a = ''
:g/^/if line('.') % 3 == 0 | yank A | endif

For explicit lines, I would sequentially call the :yank command:

2yank a | 5yank A | 27yank A

This uses yanking into the uppercase register to append to it.

like image 102
Ingo Karkat Avatar answered Feb 27 '23 22:02

Ingo Karkat