2

Say I have two windows open, and I would like to copy lines from the first window to the second window, and then move back the original window. I do this as follows:

<select lines in Visual mode>
y
Ctrl+w
w
p
Ctrl+w
w

I would like to map this to a key. My attempt is the following:

:map <F2> y :wincmd j<CR> p

It successfully copies the lines from one window to the other, but I can't seem to successfully make it jump back up to the previous window. How can I add this next part? The following does not work:

:map <F2> y :wincmd j<CR> p <ESC> :wincmd k<CR>
  • How did you manage to miss <C-w>p and :wincmd p when you read :help window-move-cursor? – romainl Mar 17 '16 at 16:03
2

Because you are in visual mode when you press F2, you need to map this key in visual mode, so you need to substitute :map for :vmap. But be careful with spaces because they move the cursor to the right in normal mode (see :help l). Here you go.

:vmap <F2> y:wincmd j<CR>p:wincmd k<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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