Execute commands in new window

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Execute commands in new window

Ven Tadipatri
Hi,
   I have a text file that I would like to sort and there's 2 things I
would like to do. First of all I would like to eliminate all duplicate
lines (this is on a linux machine). I tried :%s/\n\n/\n but though it
found the duplicate lines, it replaced it with a weird @ symbol.
  Then I would like to sort it (removing duplicates) and send the
output to a new window. I tried the following but with no luck
:new +!sort -u
:new +!sort\ -u
:new +%!sort\ -u
:new +:%!sort\ -u

When I look at the help documents, I'm not quite clear what it means
when it says you can execute a command in a new window with a +cmd. Is
that a vim command, or can I execute bash commands as well?

Thanks,
Ven

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Execute commands in new window

Christian Brabandt
Hi Ven!

On Mi, 15 Sep 2010, Ven Tadipatri wrote:

> Hi,
>    I have a text file that I would like to sort and there's 2 things I
> would like to do. First of all I would like to eliminate all duplicate
> lines (this is on a linux machine). I tried :%s/\n\n/\n but though it
> found the duplicate lines, it replaced it with a weird @ symbol.

Yeah, that is an ancient vi'ism, I believe. Use \r in the replacing
part. (see :h NL-used-for-Nul and also :h s/\r)

>   Then I would like to sort it (removing duplicates) and send the
> output to a new window. I tried the following but with no luck
> :new +!sort -u
> :new +!sort\ -u
> :new +%!sort\ -u
> :new +:%!sort\ -u

I think, you would have to double the backslashes. But I am not sure,
this does what you want. I would expect it to open a new window and in
the new empty window perform :%sort -u which is not really useful.

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Execute commands in new window

Ven Tadipatri
On Wed, Sep 15, 2010 at 2:21 PM, Christian Brabandt <[hidden email]> wrote:

> Hi Ven!
>
> On Mi, 15 Sep 2010, Ven Tadipatri wrote:
>
>> Hi,
>>    I have a text file that I would like to sort and there's 2 things I
>> would like to do. First of all I would like to eliminate all duplicate
>> lines (this is on a linux machine). I tried :%s/\n\n/\n but though it
>> found the duplicate lines, it replaced it with a weird @ symbol.
>
> Yeah, that is an ancient vi'ism, I believe. Use \r in the replacing
> part. (see :h NL-used-for-Nul and also :h s/\r)
>

Yeah the \r in the replace part worked.  That's really weird, because
though it does the right behavior, after the replace, if I search for
\r it says it can't find it, so somehow it translates \r in the
replace clause to \n in the buffer.

>>   Then I would like to sort it (removing duplicates) and send the
>> output to a new window. I tried the following but with no luck
>> :new +!sort -u
>> :new +!sort\ -u
>> :new +%!sort\ -u
>> :new +:%!sort\ -u

Anyone else have ideas on how to get this behavior to work. It seems
like something vi should be capable of doing - I want to execute a
command on the current buffer and launch it in a new one.


>
> I think, you would have to double the backslashes. But I am not sure,
> this does what you want. I would expect it to open a new window and in
> the new empty window perform :%sort -u which is not really useful.

The double backslashes didn't seem to work.
This behavior is useful because I want to compare the output before
and after the sort, in 2 separate buffers, so I don't want it to be in
the same window.

Thanks,
Ven

>
> regards,
> Christian
>

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Execute commands in new window

Benjamin R. Haskell-8
On Wed, 15 Sep 2010, Ven Tadipatri wrote:

> On Wed, Sep 15, 2010 at 2:21 PM, Christian Brabandt wrote:
>>
>> On Mi, 15 Sep 2010, Ven Tadipatri wrote:
>>
>>> [...]
>>>
>>>   Then I would like to sort it (removing duplicates) and send the
>>> output to a new window. I tried the following but with no luck
>>> :new +!sort -u
>>> :new +!sort\ -u
>>> :new +%!sort\ -u
>>> :new +:%!sort\ -u
>
> Anyone else have ideas on how to get this behavior to work. It seems
> like something vi should be capable of doing - I want to execute a
> command on the current buffer and launch it in a new one.
>
>
>>
>> I think, you would have to double the backslashes. But I am not sure,
>> this does what you want. I would expect it to open a new window and
>> in the new empty window perform :%sort -u which is not really useful.
>
> The double backslashes didn't seem to work.
> This behavior is useful because I want to compare the output before
> and after the sort, in 2 separate buffers, so I don't want it to be in
> the same window.

The following can serve as a workaround, but seems kludgy.  Since you
want to compare the output, you might want to use 'vnew' and surround it
with :diffthis'es.

" exactly as specified: (open new window with results of cmd)
let bufnum=bufnr('.') | let bufdollar=line('$') | exe "new" | call append(0,getbufline(bufnum,'1',bufdollar)) | %!sort -u

" with diffy goodness
let bufnum=bufnr('.') | let bufdollar=line('$') | diffthis | exe "vnew" | call append(0,getbufline(bufnum,'1',bufdollar)) | diffthis | %!sort -u

Though diffing doesn't really make sense after sorting.  Maybe you just
want the output of one of these (which could replaced the 'sort -u'
portion from above):

" find duplicated lines
%!sort | uniq -D

" find unmatched lines
%!sort | uniq -d

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Execute commands in new window

Simon Ruderich-2
In reply to this post by Ven Tadipatri
On Wed, Sep 15, 2010 at 05:14:13PM -0400, Ven Tadipatri wrote:
> Yeah the \r in the replace part worked.  That's really weird, because
> though it does the right behavior, after the replace, if I search for
> \r it says it can't find it, so somehow it translates \r in the
> replace clause to \n in the buffer.

It's a little confusing:

\n is \n when searching and \r when replacing.

The \r in replace is a in reality a \n. So you can't find a \r
after this replace, because Vim has replaced it with a \n. I've
no idea why this was done, but we are stuck with it.

Hope this helps,
Simon
--
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9

attachment0 (852 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Execute commands in new window

Christian Brabandt
In reply to this post by Ven Tadipatri
On Wed, September 15, 2010 11:14 pm, Ven Tadipatri wrote:
> This behavior is useful because I want to compare the output before
> and after the sort, in 2 separate buffers, so I don't want it to be in
> the same window.

You could give my NrrwRgn Plugin a try.

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php