Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy lines above the selected line in Vim

Tags:

vim

editor

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?

like image 464
vrbilgi Avatar asked Nov 08 '11 08:11

vrbilgi


2 Answers

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

like image 139
mitchnull Avatar answered Sep 17 '22 23:09

mitchnull


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)

like image 34
sehe Avatar answered Sep 17 '22 23:09

sehe