2013-04-29 107 views
1

有没有办法使用vim作为命令行工具?我的意思是,从控制台使用它(不用打开ncurses窗口)在文件上运行vim命令并保存它们。我需要这个,因为我通常会运行所有文件并执行'gg = G'来自动缩进它们。使用vim作为命令行工具?

感谢

+2

我怀疑http://stackoverflow.com/questions/3218528/indenting-in-vim-with-all-the-files- in-folder可能会帮助你。 – 2013-04-29 12:53:26

+0

请参阅http://stackoverflow.com/questions/9366243/execute-a-command-within-vim-from-the-command-line。 – 2013-04-29 12:56:27

+0

'$ vim --help'。 – romainl 2013-04-29 13:25:16

回答

2

Here列出了两种不同的方式来做到这一点:

  • 使用vim -s file-containing-commands file-to-edit

  • 使用vim file "+:firstcommand" "+:secondcommand" ...

第一种解决方案需要一个文件以前写手;第二种解决方案将启动vim并执行命令,而不会离开vim;你必须自己做,例如添加最后的命令'+:x'

+0

这对常规命令很有用,但我需要在所有内容上运行gg = G!这是我的解决方案,使用你的建议'vim file.c'+执行“normal gg = G”'+ wq'。这将直接进入我的bin文件夹;)。 – Guido 2013-04-29 20:50:22