Fedora Linux Support Community & Resources Center
  #1  
Old 16th September 2011, 07:33 PM
jimbob01 Offline
Registered User
 
Join Date: Aug 2011
Posts: 20
linuxfedorafirefox
vim - copy and paste multiple lines in script

Hi guys,

Is there a quick way in vim to copy and paste multiple (e.g. 10 lines) in a script ? One of the guys at work said earlier it can be done by using the line numbers (:set nu) but I can't remember how! Any of you guys have any idea? Been wracking by brains but i'm at a loss!

Cheers
Reply With Quote
  #2  
Old 16th September 2011, 07:51 PM
Gödel Offline
Registered User
 
Join Date: Jul 2009
Location: London,England
Posts: 1,102
linuxfedorafirefox
Re: vim - copy and paste multiple lines in script

type '10y' with cursor on first line to copy (yank 10 lines, to delete them use 10dd)

then move to (just above) paste position and hit p
Reply With Quote
  #3  
Old 16th September 2011, 08:12 PM
jimbob01 Offline
Registered User
 
Join Date: Aug 2011
Posts: 20
linuxfedorafirefox
Re: vim - copy and paste multiple lines in script

Cheers, that helps a lot!

One question though, when I do '10y' it yanks 11 lines, any ideas why ?
Reply With Quote
  #4  
Old 17th September 2011, 09:54 PM
Gödel Offline
Registered User
 
Join Date: Jul 2009
Location: London,England
Posts: 1,102
linuxfedorafirefox
Re: vim - copy and paste multiple lines in script

Quote:
Originally Posted by jimbob01 View Post
Cheers, that helps a lot!

One question though, when I do '10y' it yanks 11 lines, any ideas why ?
You're right, that seems to be a bug.
Reply With Quote
  #5  
Old 17th September 2011, 11:04 PM
jamielinux Offline
Registered User
 
Join Date: Jun 2011
Posts: 64
linuxfirefox
Re: vim - copy and paste multiple lines in script

Quote:
Originally Posted by jimbob01 View Post
Cheers, that helps a lot!

One question though, when I do '10y' it yanks 11 lines, any ideas why ?
The correct command would be '10yy'.

Quote:
Originally Posted by Gödel View Post
You're right, that seems to be a bug.
Nope. '10y<enter>' has the same effect as '10yj' (or in other words y10j). This signifies a motion of 10 lines downwards, which puts the cursor on the 11th line. Hence why 11 lines are yanked.
Reply With Quote
  #6  
Old 17th September 2011, 11:16 PM
Gödel Offline
Registered User
 
Join Date: Jul 2009
Location: London,England
Posts: 1,102
linuxfedorafirefox
Re: vim - copy and paste multiple lines in script

Quote:
Originally Posted by jnguyen View Post
The correct command would be '10yy'.

Nope. '10y<enter>' has the same effect as '10yj' (or in other words y10j). This signifies a motion of 10 lines downwards, which puts the cursor on the 11th line. Hence why 11 lines are yanked.
also the correct command would be '10Y' (shift+y = capital Y)

I just forgot uppercase Y, but you're right it's not a bug.
Reply With Quote
  #7  
Old 18th September 2011, 08:44 AM
weitjong Offline
Registered User
 
Join Date: Oct 2006
Location: Singapore, 新加坡
Posts: 944
macosfirefox
Re: vim - copy and paste multiple lines in script

I had used this counting the "number of lines" approach for quite a long time until I learn better approaches. I am sure you will agree that even with ":set nu" it is still unpractical to every time calculate the difference between end and start of lines that you want to yank or delete.

One of the easiest approach is to use the visual mode. Move the cursor to the start, then press "v" to switch on the visual mode, move the cursor to the end, then press "y" for yank command. Move the cursor position to where you want to paste, and as usual using "p" or "P" to paste the lines after or before the cursor position, respectively.

Another approach is to use "mark". Move the cursor to the start, then press "ma" to mark 'a' at current cursor position. Move the cursor to the end lines that you want to copy, then press "y'a" to yank all the lines between cursor to the mark 'a' into unnamed buffer. Then paste the yanked lines as per normal. I prefer this approach as I could define different marks (from 'a' to 'z') for different positions that I may want to jump back quickly. It can also be used in tandem with named buffer, etc.
__________________
YaoWT - Leave no window unbroken ♪ (^。^) 
Reply With Quote
  #8  
Old 18th September 2011, 04:28 PM
jimbob01 Offline
Registered User
 
Join Date: Aug 2011
Posts: 20
linuxfedorafirefox
Re: vim - copy and paste multiple lines in script

Thanks guys, helps a lot.

@weitjong - Yeah, your option does seem better, especially when I'll be counting a lot of lines to copy. Thanks again
Reply With Quote
Reply

Tags
copy, lines, multiple, paste, script, vim

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
not able to copy-paste or cut-paste adarsh.ist Using Fedora 2 9th January 2009 01:13 PM
Copy Paste in VNC rakeshgupta Using Fedora 0 24th November 2008 10:25 AM
Copy and Paste command lines bayes_fedora Using Fedora 3 12th August 2006 07:53 PM
script to do ftp? and how to access linux copy/paste buffer? Dunhausen Programming & Packaging 0 3rd May 2006 04:02 AM
copy/paste from icq.com joey111 Using Fedora 0 9th March 2006 02:05 PM


Current GMT-time: 09:24 (Thursday, 23-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Gombe Travel Photos - Tadepallegudem Photos - New Lenox Photos