can there be variables for the : command line?

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

can there be variables for the : command line?

Ramón Fallon
Hi vimmers

I use the :%s command alot for substituting, and the regexes are the
same set of 15 or 16, but each time I have to type them at the command
line. Is there a way to define a list of variables which represnt these
regexes that would be available across all my vim sessions (maybe in my
_gvimrc?) so I can type them into the command line for usage with :%s ?

Looked this up, drew no fruit, maybe because my vim lingo isn´t so good
(I get mixed up between registers and buffer half the time:-))

Cheers!

Reply | Threaded
Open this post in threaded view
|

Re: can there be variables for the : command line?

Tim Chase-2
> I use the :%s command alot for substituting, and the regexes
> are the same set of 15 or 16, but each time I have to type
> them at the command line. Is there a way to define a list of
> variables which represnt these regexes that would be available
> across all my vim sessions (maybe in my _gvimrc?) so I can
> type them into the command line for usage with :%s ?

It looks like ":ca" may be helpful...you can set up the
command-line abbreviations in your vimrc file, something like

        :cab tt s/this/that/g
        :cab fb s/foo/bar/g

You can then select ranges and do

        :'<,'>tt

which will substitute "this" with "that" over that range.

See
        :help :ca

for more on that.  You can do the same sort of thing by creating
your own vim commands with the "command" command (to overuse the
word "command").

        :help :command

This may, though, be overkill for what you describe.

[possible tangent]

If you've got more than one command you want to run, you can
stash them all in a register such as

        let @q=":%s/this/that/g\n"
        let @q=@q.":%s/foo/bar/g\n"

and then run the whole lot of commands using

        @q

in normal mode.  Note the colons and "\n" in there.  This can be
helpful if you've got the transformations in a file, such as

        foo bar
        this that
        fred barney

you can manipulate that file to become

        :%s/foo/bar/g
        :%s/this/that/g
        :%s/fred/barney/g

and they yank them into a register, and execute the contents of
that register as a macro.  It's prob. more complex than the more
simple stuff you're describing, but it's always nice to know the
option is there :)  If it's confusing, feel free to ignore this
little tangent. :)

> Looked this up, drew no fruit, maybe because my vim lingo
> isn?t so good (I get mixed up between registers and buffer
> half the time:-))

Registers are more or less a glorified clipboard.  Copy/cut
operations end up there (as do manual assignments to registers as
above, using the "@" notation).

Buffers have a fairly one-to-one mapping with files.  Exceptions
come with empty/new buffers which don't exactly have a file
associated with them yet.

It takes a while to speak "vim lingo" natively...about registers,
buffers, windows, instances of vim/gvim, arguments, previews,
quick-fix, etc.  As long as you describe what you mean, most
folks on the list can discern your intent (often correcting your
terminology to help you in the future) or will at least ask which
you meant of the two interpretations.

Hope this gives you some ideas to work with.

-tim





Reply | Threaded
Open this post in threaded view
|

RE: can there be variables for the : command line?

Halim, Salman
In reply to this post by Ramón Fallon
As an addendum, if you really, really want to store your expression in variables, you can always use <c-r>=variableName<cr> (where <c-r> means to hit the control-R and <cr> means to press Enter) on the command-line...

Hope this helps,

Salman.

> -----Original Message-----
> From: Tim Chase [mailto:[hidden email]]
> Sent: Tuesday, November 08, 2005 3:24 PM
> To: Ramón Fallon
> Cc: [hidden email]
> Subject: Re: can there be variables for the : command line?
>
> > I use the :%s command alot for substituting, and the
> regexes are the
> > same set of 15 or 16, but each time I have to type them at
> the command
> > line. Is there a way to define a list of variables which represnt
> > these regexes that would be available across all my vim sessions
> > (maybe in my _gvimrc?) so I can type them into the command line for
> > usage with :%s ?
>
> It looks like ":ca" may be helpful...you can set up the
> command-line abbreviations in your vimrc file, something like
>
> :cab tt s/this/that/g
> :cab fb s/foo/bar/g
>
---Snip---
Reply | Threaded
Open this post in threaded view
|

Re: can there be variables for the : command line? (PS)

Tim Chase-2
In reply to this post by Ramón Fallon
A second reading of your request gave me additional
thoughts...the same ":ca" can apply in this case...you can use

        :ca tt %s/this

Then you can just type

        :tt/

(in normal mode, that's "colon tee tee slash" without pressing
<enter> yet) which will expand into

        :%s/this/

leaving you able to fill in the replacement text.

Halim's suggestion of using control+R to insert the contents of a
register can help too.  It would require using a register for
each expression you wanted, unless you used the "=" register and
then put them in named variables that the "=" register can access
like Halim described.

        :help i_ctrl-R
        :he quote=

for more on register expansion and the expression register.

-tim








Reply | Threaded
Open this post in threaded view
|

Re: can there be variables for the : command line?

A.J.Mechelynck
In reply to this post by Ramón Fallon
Ram?n Fallon wrote:

> Hi vimmers
>
> I use the :%s command alot for substituting, and the regexes are the
> same set of 15 or 16, but each time I have to type them at the command
> line. Is there a way to define a list of variables which represnt these
> regexes that would be available across all my vim sessions (maybe in my
> _gvimrc?) so I can type them into the command line for usage with :%s ?
>
> Looked this up, drew no fruit, maybe because my vim lingo isn?t so good
> (I get mixed up between registers and buffer half the time:-))
>
> Cheers!

A _buffer_ contains a file; it may, but need not, be displayed in a
window. The list of buffers can be displayed by ":buffers" (or
":buffers!" if you also want unlisted buffers).

A _register_ contains something which has been yanked or deleted, or can
be put. It can also contain a keyboard macro. The clipboard is reflected
in one (or two) of Vim's registers. The contents of the registers can be
displayed by ":registers".

Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

RE: can there be variables for the : command line? (PS)

Ramón Fallon
In reply to this post by Tim Chase-2

Those were just incredible answers, thanks so much! And so quickly too.
Actually as soon as I saw the "cab" structure the penny fell into place,
basically because I already have plenty of iab's in my _gvimrc. It made
immediate logical sense. The other clarifications are also much
appreciated. So all solved! You guys are better than perlmonks.org (who
are already very cool)!