Sagar Jain
Sagar Jain

Reputation: 7941

How to copy a specific line in vim from current position?

How to copy a specific line in vim from current position, without moving to that specific line? Suppose, in the below code, if my cursor is in line no. 891 and I want to copy a line, say line no. 899. How do I do it without actually moving to the line 899, pressing yy and come back to 891 ?

885 int __pm_runtime_idle(struct device *dev, int rpmflags)
886 {
887         unsigned long flags;
888         int retval;
889 
890         might_sleep_if(!(rpmflags & RPM_ASYNC) && !dev->power.irq_safe);
891 
892         if (rpmflags & RPM_GET_PUT) {
893                 if (!atomic_dec_and_test(&dev->power.usage_count))
894                         return 0;
895         }
896 
897         spin_lock_irqsave(&dev->power.lock, flags);
898         retval = rpm_idle(dev, rpmflags);
899         spin_unlock_irqrestore(&dev->power.lock, flags);
900 
901         return retval;
902 }

Upvotes: 3

Views: 945

Answers (4)

user3484656
user3484656

Reputation:

In general

to yank,

:line#y

to yank & paste in next line

:line#t.

to delete

:line#d

All the above can be applied to a block of lines as well..

to yank from line 10 to line 20

:10,20y

Upvotes: 5

Ingo Karkat
Ingo Karkat

Reputation: 172748

My LineJuggler plugin has a fetch mapping that works with relative addressing, which is faster and (especially with :set relativenumber) easier than typing the full line number (as in the other answers).

Your particular example would be 8[f (fetch from 8 lines below the current line).

Upvotes: 2

Kent
Kent

Reputation: 195229

this short cmd will help you

:899t.

it will copy the line 899 and paste under your cursor line.

and without touching the " register.

Upvotes: 14

Thor
Thor

Reputation: 47219

Use the yank command:

:899y

This will copy line 899 to the unnamed register.

Upvotes: 7

Related Questions