Creating an autocmd with 2 :g commands

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

Creating an autocmd with 2 :g commands

David Fishburn

Vim 6.3.75 WinXP SP2

I am trying to do the following:
1.    autocmd BufReadPost cscope.files :g/lib/d | :g/html/d
2.    autocmd BufReadPost cscope.files :g/lib/d \| :g/html/d

Essentially, when I open a file, just run a couple of :g and :v commands to
clean it up.

If I use 1., then I get:
Error detected while processing BufRead Auto commands for "cscope.files":
E147: Cannot do :global recursive

So I tried using \| between them instead.
That executes the first one, but not the second.

I also tried <bar>, but I think that is only for maps, not autocmds.

Not sure why I get the E147.  I am not attempting a recursive g command, I
just want to run 2 in a row.
I have added <CR>s at each of the commands as well, but then I get "Trailing
spaces" errors.

:h E147 does not help me in this case.

Suggestions?

Thanks,
Dave

Reply | Threaded
Open this post in threaded view
|

Re: Creating an autocmd with 2 :g commands

Marian Csontos
Hi David,

try
        autocmd BufReadPost cscope.files exec "g/lib/d" | exec "g/html/d"

Regards

-- Marian

On Thu, 07 Jul 2005 17:30:51 +0200, David Fishburn  
<[hidden email]> wrote:

>
> Vim 6.3.75 WinXP SP2
>
> I am trying to do the following:
> 1.    autocmd BufReadPost cscope.files :g/lib/d | :g/html/d
> 2.    autocmd BufReadPost cscope.files :g/lib/d \| :g/html/d
>
> Essentially, when I open a file, just run a couple of :g and :v commands  
> to
> clean it up.
>
> If I use 1., then I get:
> Error detected while processing BufRead Auto commands for "cscope.files":
> E147: Cannot do :global recursive
>
> So I tried using \| between them instead.
> That executes the first one, but not the second.
>
> I also tried <bar>, but I think that is only for maps, not autocmds.
>
> Not sure why I get the E147.  I am not attempting a recursive g command,  
> I
> just want to run 2 in a row.
> I have added <CR>s at each of the commands as well, but then I get  
> "Trailing
> spaces" errors.
>
> :h E147 does not help me in this case.
>
> Suggestions?
>
> Thanks,
> Dave
>
>
>
> ________ Information from NOD32 ________
> This message was checked by NOD32 Antivirus System for Linux Mail Server.
> http://www.nod32.com
>
>
> __________ Informacia od NOD32 1.1162 (20050706) __________
>
> Tato sprava bola preverena antivirusovym systemom NOD32.
> http://www.eset.sk
>
>



--
Mgr. Mari?n Csontos
program?tor POS
AXA, a.s.
Radni?n? n?mestie 4
821 05 Bratislava
tel. +421 2 4829 4218
mailto:[hidden email]
www.axa.sk
 


________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com
Reply | Threaded
Open this post in threaded view
|

Re: Creating an autocmd with 2 :g commands

John (Eljay) Love-Jensen
In reply to this post by David Fishburn
Hi David,

Try this:
autocmd BufReadPost cscope.files :g/lib/d
autocmd BufReadPost cscope.files :g/html/d

--Eljay

Reply | Threaded
Open this post in threaded view
|

Re: Creating an autocmd with 2 :g commands

Tim Chase-2
In reply to this post by David Fishburn
> I am trying to do the following:
> 1.    autocmd BufReadPost cscope.files :g/lib/d | :g/html/d
> 2.    autocmd BufReadPost cscope.files :g/lib/d \| :g/html/d
[cut]
> Not sure why I get the E147.  I am not attempting a recursive
> g command, I just want to run 2 in a row.

The :g command slurps up things that follow it and tries to
execute them as part of the stuff it does on each line.  Thus the
"you can't recurse" annoyance.  You have to wrap at least the
first one in an exec() call such as

autocmd BRP cscope.files exec(":g/lib/d") | g/html/d

You can do the second one as well, but it's a but
superfluous...you just have to make sure that for N :g commands,
at least 1...N-1 of them are wrapped in exec() calls.

Alternative #1:  issue two autocmd statements:
autocmd BRP cscope.files :g/lib/d
autocmd BRP cscope.files :g/html/d

Alternative #2:  combine the regexp and do it in one pass:
autocmd BRP cscope.files :g/lib\|html/d

Cat's getting skinned all sorts of ways :)

-tim




Reply | Threaded
Open this post in threaded view
|

Re: Creating an autocmd with 2 :g commands

Marian Csontos
In reply to this post by Marian Csontos
Or even better:
        autocmd BufReadPost cscope.files g/lib\|html/d

On Thu, 07 Jul 2005 17:39:41 +0200, Marian Csontos <[hidden email]> wrote:

> Hi David,
>
> try
> autocmd BufReadPost cscope.files exec "g/lib/d" | exec "g/html/d"
>
> Regards
>
> -- Marian
>
> On Thu, 07 Jul 2005 17:30:51 +0200, David Fishburn  
> <[hidden email]> wrote:
>
>>
>> Vim 6.3.75 WinXP SP2
>>
>> I am trying to do the following:
>> 1.    autocmd BufReadPost cscope.files :g/lib/d | :g/html/d
>> 2.    autocmd BufReadPost cscope.files :g/lib/d \| :g/html/d
>>
>> Essentially, when I open a file, just run a couple of :g and :v  
>> commands to
>> clean it up.
>>
>> If I use 1., then I get:
>> Error detected while processing BufRead Auto commands for  
>> "cscope.files":
>> E147: Cannot do :global recursive
>>
>> So I tried using \| between them instead.
>> That executes the first one, but not the second.
>>
>> I also tried <bar>, but I think that is only for maps, not autocmds.
>>
>> Not sure why I get the E147.  I am not attempting a recursive g  
>> command, I
>> just want to run 2 in a row.
>> I have added <CR>s at each of the commands as well, but then I get  
>> "Trailing
>> spaces" errors.
>>
>> :h E147 does not help me in this case.
>>
>> Suggestions?
>>
>> Thanks,
>> Dave
>>
>>
>>
>> ________ Information from NOD32 ________
>> This message was checked by NOD32 Antivirus System for Linux Mail  
>> Server.
>> http://www.nod32.com
>>
>>
>> __________ Informacia od NOD32 1.1162 (20050706) __________
>>
>> Tato sprava bola preverena antivirusovym systemom NOD32.
>> http://www.eset.sk
>>
>>
>
>
>



--
Mgr. Mari?n Csontos
program?tor POS
AXA, a.s.
Radni?n? n?mestie 4
821 05 Bratislava
tel. +421 2 4829 4218
mailto:[hidden email]
www.axa.sk
 


________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com
Reply | Threaded
Open this post in threaded view
|

RE: Creating an autocmd with 2 :g commands

David Fishburn
In reply to this post by Tim Chase-2
Thanks for all the responses.

This is what I finished with:

    autocmd BufReadPost cscope.files
                \ let before_lines = line('$') |
                \ silent! exec 'silent!
g/\(cscope\|\.\(gif\|bmp\|png\|jpg\|swp\)\)/d' |
                \ silent! exec 'silent! v/\./d' |
                \ let before_lines = before_lines - line('$') |
                \ if before_lines > 0 |
                \   call confirm( 'Removed ' . before_lines . ' lines from
file.  ' .
                \           'These were any of the following: ' .
                \           "\n".'- image and swap files ' .
                \           "\n".'- directories ' .
                \           "\n".'- any cscope files.' .
                \           "\n\n".'Press u to recover these lines.'
                \           ) |
                \ endif

Even get confirmation it has happened, wow!  :-)

Dave