vrbilgi
vrbilgi

Reputation: 5793

How to copy lines above the selected line in Vim

I want to copy N lines above the selected position. yNy works for copying the below N lines.

What is the command for copy N line above the selected position?

Upvotes: 8

Views: 4564

Answers (2)

mitchnull
mitchnull

Reputation: 6331

yNk will copy the line you're on and the N preceding lines.

Upvotes: 13

sehe
sehe

Reputation: 392833

Or, use :<range>yank (see :he range for all possible uses of range)

:-3,-1y

this does precisely what you ask: yank only (e.g. 3) lines before the current line. You could

:-1y
:-2y

to yank just the previous (or pre-previous) line etc...

:1,-1y

to yank everything till the last line

:1,.y

for that including the current line (of course, you could do that with ygg)

Upvotes: 4

Related Questions