LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-31-2009, 02:44 AM   #1
hadimotamedi
Member
 
Registered: Aug 2009
Posts: 228

Rep: Reputation: 30
Inquiry:How to copy/paste in vi text editor


Dear All
Can you please do me favor and let me know how can I copy lengthy strings from one text file and paste it into another text file in vi text editor ?
Regards
H.Motamedi
 
Old 08-31-2009, 02:52 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
vi both files by giving both as arguments on the command line. At first use :n to go to the next file then use :# to switch between files. Go to the file you want to copy text from. Name a buffer with "a (the a can be any letter). Copy stuff into the buffer in the normal way, maybe yy, 5yy, y5G whatever. Use :# to switch to the other file. Nominate the same buffer with "a and then put in the normal way, maype p, P whatever.
 
Old 08-31-2009, 02:53 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Here comes a step-by-step guide:
1. Edit the file from which you want to copy text
2. Put the cursor onto the upper line to be copied
3. Mark this line (press ma in sequence)
4. Go to the lower line to be copied
5. Pull the text from the current location to the line marked with a (press y'a in sequence)
6. Open the file to paste the text into in the same terminal using the vi command :split filename
7. Go to the line where the insertion is needed
8. Paste the text after the cursor (press p)
9. Save and quit.
Hope this helps!
 
Old 08-31-2009, 03:07 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Another way (using visual mode):
1. Edit the file from which you want to copy text
2. Put the cursor onto the upper line to be copied
3. Switch to visual mode (press uppercase V). The line will be highlighted.
4. Go to the lower line to be copied. All the text between the two lines will be highlighted.
5. Yank the text (press y)
6. Open the file to paste the text into in the same terminal using the vi command :split filename
7. Go to the line where the insertion is needed
8. Paste the text after the cursor (press p)
9. Save and quit.
 
Old 08-31-2009, 03:09 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Hello Colucix :split's nice; how do you jump from file to file on screen?

Last edited by catkin; 08-31-2009 at 03:10 AM. Reason: Typo
 
Old 08-31-2009, 03:20 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by catkin View Post
Hello Colucix :split's nice; how do you jump from file to file on screen?
Hi catkin! To move between splitted windows you can try Ctrl-w + Arrow down and Ctrl-w + Arrow up to move down and up respectively.
 
Old 08-31-2009, 03:46 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by colucix View Post
Hi catkin! To move between splitted windows you can try Ctrl-w + Arrow down and Ctrl-w + Arrow up to move down and up respectively.
That's going to be useful
 
Old 08-31-2009, 06:58 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
I usually just highlight src with the mouse, then 'i' insert mode on in target file and mouse-paste.
For large inserts, get the src txt into a file, then in the target file, move the cursor to where you need the insert, then

:r srcfile


to insert.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to copy/paste a line in nano editor smp0219 Linux - Newbie 7 01-03-2016 06:40 PM
Copy Text File and Paste to /hdd CD-RW aquatux SUSE / openSUSE 3 12-29-2006 06:32 AM
Which light text editor can copy text from file and paste in browser? davidas Linux - Software 9 03-06-2006 11:28 AM
CLI copy & paste between text files? David the H. Linux - General 3 09-15-2004 12:05 PM
How to copy/paste text from boot, nongui Eradicator Linux - Newbie 2 10-31-2003 05:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration