Newbie question: How to give a command over they current file and all other files in directory

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

Newbie question: How to give a command over they current file and all other files in directory

Eric Leenman
Hi,

If I have one file open in gVim, say file1.c,
how can I give a command in gVim which would apply to file1.c but also
to all other .c files in the directory which are not open in gVim?

For Example to:
- rename everywhere global var gWriteFlag into gWrFlg
:%s/gWriteFlag/gWrFlg
- to remove all spaces at the end of lines
:%s=  *$==


Rgds,
Eric


Disclaimer; The information contained in this communication is confidential
and may be legally privileged. It is intended solely for the use of the individual
or entity to whom it is addressed and others authorized to recieve it.
Use of this information, in whatever way, by others is strictly prohibited
and may be unlawful. GREEFA does not accept legal responsibility
for this e-mail message due to the insecure nature of internet
communications.  
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question: How to give a command over they current file and all other files in directory

A.J.Mechelynck
----- Original Message -----
From: "Eric Leenman" <[hidden email]>
To: "vim" <[hidden email]>
Sent: Wednesday, September 28, 2005 10:28 AM
Subject: Newbie question: How to give a command over they current file and
all other files in directory


> Hi,
>
> If I have one file open in gVim, say file1.c,
> how can I give a command in gVim which would apply to file1.c but also
> to all other .c files in the directory which are not open in gVim?
>
> For Example to:
> - rename everywhere global var gWriteFlag into gWrFlg
> :%s/gWriteFlag/gWrFlg
> - to remove all spaces at the end of lines
> :%s=  *$==
>
>
> Rgds,
> Eric

    " change to directory of current file
    :cd %:p:h
    " define new arguments list
    :args *.c
    " do something on all files in the list
    :argdo 1,$s/\<gWriteFlag\>/gWrFlg/g
or
    :argdo 1,$s/\s*$//

Note: for the first substitution, you will probably want to check for word
boundaries (not replace BlogWriteFlaggingRoutine by BlogWrFlggingRoutine)
and replace all matches, even several on a line (hence the g flag).

    see
        :help :args
        :help :argdo


HTH,
Tony.