linux - 将 VIM 键序列应用于目录中的所有文件

标签 linux shell vim

<分区>

我想使用 VIM 的 gg=G 命令缩进我所有的文件。有没有办法编写一个脚本来做到这一点?

我想它可能是这样的

find . | xargs -n 1 | vim [ with some option to indent ]

我很确定 vim -c 可能有帮助,但不确定什么是 gg=G 等价物..

最佳答案

vim 有两个选项你可以看看:(来自 man vim)

 -s {scriptin}
                   The script file {scriptin} is read.  The characters in the file are interpreted as if you had typed them.  The same can be  done  with  the  command
                   ":source! {scriptin}".  If the end of the file is reached before the editor exits, further characters are read from the keyboard.

  -w {scriptout}
               All the characters that you type are recorded in the file {scriptout}, until you exit Vim.  This is useful if you want to create a script file to be
               used with "vim -s" or ":source!".  If the {scriptout} file exists, characters are appended.

这意味着,你可以通过 vim -w script 记录你的键序列,例如 gg=GZZ 然后你可以 vim -s script file

我想 vimgolf 也使用了这种机制。

关于linux - 将 VIM 键序列应用于目录中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16423650/

相关文章:

sql-server - 使用 Microsoft SQL Server 查询时如何获取计时

json - 使用 JQ 从文件中删除重复的 JSON block

Vim 对象选择与语法感知文本对象

VIM:更改与/搜索匹配的当前突出显示的搜索词

linux - 如何在 Linux 中使用 NASM 汇编获取系统时间而不使用从 C 导出的函数?

java - 为什么从 Java 应用程序运行 MAKE 会导致出现错误消息?

linux - 在日志文件中与脚本 shell (linux 批处理)和重定向融洽相处

java - 在 Java 中生成带参数的 linux 命令

linux - 在 Linux DR 数据库服务器重新启动期间安全停止和重新启动 Oracle Golden Gate 复制的过程

vim - 如何在 Vim 中映射特定文件类型的键?