I find myself doing the following very often: xkyyxjp (where x is a number).

I copy a whole line x lines up, and then I paste it x lines down (and vice versa); and so I wanted to make a map so I can do it automatically, ideally with: x<Leader>u, where x is the number and u is the letter that indicates the mapping. I tried:

nnoremap <Leader>u @='jyy'<CR>


nnoremap <expr> <Leader>u v:count1 kyy v:count1 jp

How could I write said mapping? Is there an already built-in key that does this?

1 Answer 1


You can use :copy or a shortcut :t command for that:


it will copy line 10 below line 20.

Or copy 10 previous lines below line 20:


Instead of copying text directly to the buffer you can use :yank or :y command instead to yank lines:


and then paste with p. This you can map as:

nnoremap <space>u <cmd>exe "-" .. (v:count1 - 1) .. ",y"<CR>

Where :exe executes a "string" you can construct with string concatenation ... And <cmd>expression<cr> is the way to execute a command without changing modes.

If you want to yank a single line located before cursor then :-10y should do it, and a mapping:

nnoremap <space>u <cmd>exe "-" .. v:count1 .. "y"<cr>
  • Hi maxim, thanks for the reply. The thing is (maybe I am misinterpreting this), but I belive that mapping copies a whole bunch of lines. Where instead, I just want to copy a single line that is x lines up, and paste it x lines down. Is there a way to do that instead? Dec 5, 2022 at 11:52
  • @PeterPetigru it should be easier then, :-10y
    – Maxim Kim
    Dec 5, 2022 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.