LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 05-06-2010, 03:10 AM   #1
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908
Blog Entries: 26

Rep: Reputation: 49
sorting in vi editor & copying to clipboard


Question
(1)There should be a command to send content to clipboard instead of 36 buffers available in vi just like ':set paste' allows pasting from clipboard inside vi using ctrl+shift+v in insert mode.(Currently I select area using mouse & right click then copy )


(2)Let us say I have sentence "I am young"
I want to arrange the words in this line in alphabetical order so that I get 'am I young'.
First I thought replacing space by \r in sentence.Then !#j then type sort -n where # represents number of words.Then #J to join the filteredlines.It works but now I have file with hundreds of sentence of varying length.If I make a macro how will it know the number of words ?
 
Old 05-06-2010, 06:47 AM   #2
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
This all depends on which vi you use. Are you using Vim? (Your mention of the :set paste option implies that you are.) If so, the "+ register holds the contents of the system clipboard. If you are using X Window, (Again, your mention of the selection buffer implies that you are.) the "* also contains the contents of the current X selection.

"+y to copy to the system clipboard
"+d to "cut" to the system clipboard
"+p to paste from the system clipboard
"*p to paste from the X Window selection buffer

Your second question is answered directly at http://stackoverflow.com/questions/1...t-lines-in-vim. The solution there can be made into a macro very easily.
 
Old 05-06-2010, 09:36 AM   #3
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
For benefit of all users
I found that
Code:
:.!tr ' ' '\n' | sort | tr '\n' ' '
Also this worked (though I don't understand it)
Code:
:call setline('.', join(sort(split(getline('.'), ' ')), " "))
Both of the above sorted the words in a line.

to penguiniator
"*p,"+p did not paste contents of clipboard.

I am using vim in ubuntu 8.04.

Last edited by sumeet inani; 05-06-2010 at 11:53 PM.
 
Old 05-06-2010, 09: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
To use the clipboard facilities, your version of vim should be compiled with X clipboard support. To verify this try
Code:
vim --version
and look at +clipboard and +xterm_clipboard (support on) or -clipboard and -xterm_clipboard (support off).

Last edited by colucix; 05-06-2010 at 10:05 AM. Reason: forgot the +clipboard flag
 
Old 05-06-2010, 11:01 PM   #5
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
Another question
Suppose I have line
Code:
NET __WIFI_LINK_ DS20-1 U9-AA22
I want to prefix __WIFI_LINK_ to all other words that follow it.I want
Code:
NET __WIFI_LINK_ __WIFI_LINK_DS20-1 __WIFI_LINK_U9-AA22
I have file containing lots of such sentences then I will make a macro.Problem is I want to replace space in sentence with word just copied in present line.i.e
:s/ / WordCopied/g
what should I mention for WordCopied ?
(answer) use ctrl+rREGISTER_NAME to get its content in ex-mode.
By default contents are copied to " register if you don't mention a-z.

Last edited by sumeet inani; 05-07-2010 at 01:19 AM. Reason: For benefit of all
 
Old 05-07-2010, 01:20 AM   #6
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
to colucix
Mine says
$vim --version | grep -i clipboard
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
-xterm_clipboard -xterm_save

As you said colucix , this means support is off.
What can i do ?
 
Old 05-07-2010, 01:36 AM   #7
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
If the terminal emulator you are using supports copy-and-paste then you can copy the word and then paste it after entering ":s/ / "

Last edited by catkin; 05-07-2010 at 01:37 AM. Reason: allows->supports
 
Old 05-07-2010, 03:16 AM   #8
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
:s/ / means replace space by space in current line.
Catkin, Are you talking about 'another question'.
In that my query was to copy word from register . With every line Contents of register change as macro copies second word in corresponding line.
 
Old 05-07-2010, 04:19 AM   #9
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 sumeet inani View Post
As you said colucix, this means support is off. What can i do?
You should either install a vim package compiled with clipboard support or compile it from source by yourself. Well.. if you're running Ubuntu (as we can see from the Ubuntu icon in your posts) the mentioned package is vim-full.
 
Old 05-07-2010, 04:24 AM   #10
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
thank you colucix
Now i have + & * register which has contents of clipboard & selection buffer respectively (Great info penguiniator).

I did
#apt-get install vim-full
Now I have
$ vim --version | grep -i clipboard

+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+xterm_clipboard -xterm_save

I think x window selection buffer is the one we select using mouse in terminal or/and visual in vi & pasted in another application using middle mouse button while contents of clipboard using paste option.

Last edited by sumeet inani; 05-07-2010 at 04:40 AM.
 
  


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
Bash script for sorting out FSTAB & mount points ? Sparxz Linux - Newbie 1 05-30-2009 07:04 PM
Clipboard content get pasted randomly ( Suse & Ubuntu ) hyapadi Linux - Laptop and Netbook 6 07-09-2006 05:20 AM
Copying xterm or rxvt messages to clipboard vharishankar Linux - General 2 04-04-2006 08:49 PM
gtk dialogs & case sensitive sorting palceksmuk Linux - Software 0 03-11-2006 02:12 PM
Sylpheed 1.7.9 - Addr Book & Sorting issues ? Sader Linux - Software 0 04-06-2005 01:06 AM

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

All times are GMT -5. The time now is 10:05 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
Open Source Consulting | Domain Registration