execute key strokes from a file

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

execute key strokes from a file

Peng Yu
Hi,

I'm wondering if there is a way to execute key strokes from a file.

For example, I want to open a file main.vim, then type i, CTRL-R, %,
which type the filename main.vim in the file. The I type ESC and :wq
to save the file and quit. Is there a way to automate the whole
process in a script?

Regards,
Peng

--
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 key strokes from a file

Marcin Szamotulski
On 09:33 Mon 10 Dec     , Peng Yu wrote:

> Hi,
>
> I'm wondering if there is a way to execute key strokes from a file.
>
> For example, I want to open a file main.vim, then type i, CTRL-R, %,
> which type the filename main.vim in the file. The I type ESC and :wq
> to save the file and quit. Is there a way to automate the whole
> process in a script?
>
> Regards,
> Peng
>
> --
> 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

I am not sure if this is what you want:  you can use :argdo (or :windo,
:bufdo - what fit you better) with

:argdo normal i %
:wa

There to type   you need to press ^V^R (i.e. CTRL-V followed by
CTRL-R), to type   you need ^V<Esc> (i.e. CTRL-V followed by the <Esc>
key).

Best,
Marcin

--
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 key strokes from a file

Benjamin Fritz
In reply to this post by Peng Yu
On Monday, December 10, 2012 11:33:36 AM UTC-6, Peng Yu wrote:
>
> I'm wondering if there is a way to execute key strokes from a file.
>

Yes, there is.

See :help :source. If you use ":source!" the file is read as if typed from normal mode. If you use ":source" the file is read as a series of ex commands.

See :help -w for how to create such a file.

You can also record a macro to do all the actions you want and run the macro in a bufdo or windo or tabdo command. I do this from time to time when I want to repeat a bunch of commands on a bunch of files.

--
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