How to copy lines above a selected line in Vim

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

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

+7
source share
2 answers

yNk will copy the line you are in, and the N preceding lines.

+10
source

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

 :-3,-1y 

this does exactly what you are asking for: keep only (e.g. 3) lines in front of the current line. You could

 :-1y :-2y 

to display only the previous (or previous) line, etc.

 :1,-1y 

to pull everything to the last line

 :1,.y 

for this, including the current line (of course, you can do this with ygg )

+4
source

All Articles