yanking by line number in vim

vim, yank

Solution

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.

Problem

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

Original source