How can I yank and paste Line 4 only to Line 12 without having to move the cursor to Line 4?
Others have already mentioned the most direct method of doing this, which is
:4y, but I want to add two notes about it which may be useful:
One, if you type in
:help range you will learn all about using ranges to apply to Ex style commands. VERY useful in many cases, and far more versatile than using line numbers. For instance, if you want to yank the first line starting with "yank" after the start of the document (even if it's on the first line), use
:0/^yank/y. The most powerful part of ranges is the ability to combine them, e.g.,
:./^Chapter/+50?Pete?d means "Find the next line to start with the word Chapter (searching forward from the current line), then jump forward 50 lines, and search backward for the word Pete, and delete the first line you find it in." Except that it doesn't actually move the cursor, it just DOES what you tell it.
(I've used this type of range specification to automate fiddly documentation creation involving searching for the function name under the cursor, then searching forward for the next line which said "Description" and yanking it to a specific register...etc.)
The other tip, is that you should know about jumping. Type
:help jump-motions to learn about it fully, but the way it relates here is that you can jump to line 4, yank it and then RETURN with
4Gyy'' (or use backticks instead of apostrophes to jump back to your exact starting position, rather than just the same LINE you started at.)
:1t. copies the first line below the current.
:1,4t. copies line 1 to 4 (inclusive) below the current.
Also possible with relative line numbers:
:-1t. copies the previous line below the current.
In your example
:4t-1 would copy the fourth line below the wanted line.
:t is a synonym for the