如何在命令提示符下运行一系列vim命令 [英] How to run a series of vim commands from command prompt

查看:72
本文介绍了如何在命令提示符下运行一系列vim命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个文本文件A.txt,B.txt,C.txt和D.txt
我必须在所有这些文件中执行一系列vim编辑。
当前我的工作方式是打开每个文件,并一步一步地执行相同的vim命令。

I have four text files A.txt, B.txt, C.txt and D.txt I have to perform a series of vim editing in all these files. Currently how I am doing is open each files and do the same vim commands one by one.

是否可以制作一个可以运行的脚本文件在命令提示符下,意味着无需打开实际文件即可进行vim编辑。

Is it possible to make a script file which I can run from the command prompt, means without open the actual file for vim editing.

例如,如果我必须在打开A.txt文件后执行以下vim命令, vim编辑器:

for example, if I have to perform the below vim commands after opening the A.txt file in vim editor:

:g/^\s*$/d
:%s/^/[/
:%s/\(.*\)\(\s\+\)\(.*\)/\3\2\1
:%s/$/]/
:%s/design/test/

是可以制作一个脚本文件并放置所有这些命令,包括 gvim A.txt (文件中的第一个命令)。
并在命令提示符下编辑运行脚本文件。

Is it possible to make a script file and put all these commands including gvim A.txt (first command in the file). and edit run the script file from command prompt.

如果可能的话,请让我知道如何做以及如何通过单个命令完成或一次一次有多个文件?

If it is possible, please let me know how to do it and how it can be done with single or multiple files at a time?

推荐答案

vim -c <command> Execute <command> after loading the first file

执行您所描述的操作,但必须在一个位置执行

Does what you describe, but you'll have to do it one file at a time.

因此,在Windows Shell中...

So, in a windows shell...

for %a in (A,B,C,D) do vim -c ":g/^\s*$/d" -c "<another command>" %a.txt

POSIX的外壳很相似,但是前面没有机器

POSIX shells are similar, but I don't have a machine in front of me at the moment.

我想您可以一次加载所有文件并执行该操作,但这需要在vim命令行上为每个文件重复命令,类似

I imagine you could load all the files at once and do it, but it would require repeating the commands on the vim command line for each file, similar to

vim -c "<command>" -c "<command>" -c ":n" (repeat the previous -c commands for each file.)  <filenames go here>

编辑:2014年6月8日:
仅供参考,我是在几分钟前发现的

June 08 2014: Just an FYI, I discovered this a few minutes ago.

vim具有命令bufdo来对编辑器中加载的每个缓冲区(文件)执行操作。查看bufdo命令的文档。在vim中,:help bufdo

vim has the command bufdo to do things to each buffer (file) loaded in the editor. Look at the docs for the bufdo command. In vim, :help bufdo

这篇关于如何在命令提示符下运行一系列vim命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆