Wednesday, September 15, 2010

Re: Execute commands in new window

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

No comments: