LinuxQuestions.org
Register a domain and help support LQ
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, 04:10 AM   #1
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Rep: Reputation: 48
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, 07: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, 10:36 AM   #3
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
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-07-2010 at 12:53 AM.
 
Old 05-06-2010, 10:56 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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 11:05 AM. Reason: forgot the +clipboard flag
 
Old 05-07-2010, 12:01 AM   #5
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
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 02:19 AM. Reason: For benefit of all
 
Old 05-07-2010, 02:20 AM   #6
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
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, 02:36 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
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 02:37 AM. Reason: allows->supports
 
Old 05-07-2010, 04:16 AM   #8
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
: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, 05:19 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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, 05:24 AM   #10
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
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 05:40 AM.
 
  


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


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