LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 11-20-2010, 04:03 AM   #1
aceone
Member
 
Registered: Apr 2009
Posts: 55

Rep: Reputation: 15
copying selected text using vi


hi,
how can i copy and paste selected text from one file to other using vi in RHEL5.i googled and found some methods,like

just use m to mark the start, with an arbitrary buffer name (so you might type mx). Move your cursor down to where you want to stop copying, and type y'x (or d'x if you're cutting and pasting). Then move the cursor to the point where you want to paste, and type p.

when i do this it pastes the entire line of which a part is selected so in essence it is working as yy.
when i open a new file using vi and try to paste it says "nothing in register".what i exactly want to do is copy only the selected text as shown above in red and paste it in a new file.
plz guide

thanks & regards
 
Old 11-20-2010, 04:23 AM   #2
honeybadger
Member
 
Registered: Aug 2007
Location: India
Distribution: Slackware (mainly) and then a lot of others...
Posts: 855

Rep: Reputation: Disabled
I found a way out to deal with this one
You have to open the file in a new tab (esc :newtab) and than press 'p' and it would be pasted.
Hope this works for you too.
 
Old 11-20-2010, 04:25 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by aceone View Post
when i do this it pastes the entire line of which a part is selected so in essence it is working as yy.
To copy part of a line you can simply use the y (yank) command:
Code:
yw   copies a single word
yNw  where N is a number copies N words
ye   avoids copying the blank space after the word
yNe  same as above for multiple words
y$   copies form the cursor position to the end of the line
To paste it into another file, you can copy the text, then edit another file inside the same vi session using the edit command
Code:
:e newfile
and paste with p. Hope this helps.
 
Old 11-20-2010, 04:56 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I forgot to mention that you can copy/paste any portion of text by entering in Visual Mode. Just press v to switch to visual, then move the cursor using the arrows keys to select text, then use y and p to copy and paste respectively.
 
Old 11-20-2010, 05:50 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
According to Hewlett Packard's excellent "The Ultimate Guide to the vi and ex Text Editors", the ʾ is used for marking lines and the ʻ for marking character positions. In case you can't see the difference the first is a closing single quote and the second an opening single quote, the characters that are sometimes known as "smart single quotes" in word-processing, hex codes 02BE and 02BB.

That's not much use on IBM-PC style keyboards which have neither. The ' character which they do have is treated as the closing single quote so is a line marker as described earlier.

If using a terminal with copy and paste facilities the text can be copied and pasted, the pasting working as if the text were typed so best to be in input mode! The copy will also copy line numbers if displayed so :se nu! is useful.

Vim is hugely configurable so it may be possible to redfine some other character to be equivalent to the opening single quote.

Last edited by catkin; 11-20-2010 at 05:59 AM. Reason: subediting
 
Old 11-20-2010, 05:53 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by colucix View Post
I forgot to mention that you can copy/paste any portion of text by entering in Visual Mode. Just press v to switch to visual, then move the cursor using the arrows keys to select text, then use y and p to copy and paste respectively.
Hi colucix That's a nice technique, new to me.
 
Old 11-20-2010, 05:59 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by catkin View Post
Hi colucix That's a nice technique, new to me.
Hi catkin! Just noticed you've reached 5000 posts and acquired the guru title... congratulations!

Sorry for the off-topic.
 
Old 11-20-2010, 06:01 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by colucix View Post
Hi catkin! Just noticed you've reached 5000 posts and acquired the guru title... congratulations!
Thank you kindly.
 
  


Reply



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
XEmacs deleting/overwriting selected text hyperriven Linux - Desktop 1 09-29-2011 11:22 AM
openoffice 2.4 text field cannot be selected 105659 Linux - Software 4 06-23-2008 11:29 AM
Cannot print selected text dwhitney67 Linux - General 0 09-30-2007 12:42 AM
VI : Copying Selected Text Chaitanyayardi Linux - Software 1 11-10-2005 07:40 AM
How to change the selected text color in nedit? ICO Linux - Software 3 03-18-2004 09:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 09:38 AM.

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
Open Source Consulting | Domain Registration