LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Inquiry:How to copy/paste in vi text editor (https://www.linuxquestions.org/questions/linux-newbie-8/inquiry-how-to-copy-paste-in-vi-text-editor-751415/)

hadimotamedi 08-31-2009 02:44 AM

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

catkin 08-31-2009 02:52 AM

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.

colucix 08-31-2009 02:53 AM

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! :)

colucix 08-31-2009 03:07 AM

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.

catkin 08-31-2009 03:09 AM

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

colucix 08-31-2009 03:20 AM

Quote:

Originally Posted by catkin (Post 3663611)
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.

catkin 08-31-2009 03:46 AM

Quote:

Originally Posted by colucix (Post 3663622)
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 :)

chrism01 08-31-2009 06:58 PM

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.


All times are GMT -5. The time now is 07:48 PM.