本文介绍了如何写一个bash脚本使用分裂和标签的Vim打开多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图自动化一些体力劳动,使用bash脚本。基本上我在1终端窗口(并且只有一个终端选项卡)打开多个文件用Vim,使用多个分裂,vsplits和标签。我现在介绍一个一般的情况下,解释什么,我通常会做手工。

I am trying to automate some manual labor, using a bash script. Basically I open multiple files with Vim in 1 terminal-window (and only one terminal-tab), using several splits, vsplits and tabs. I will now describe a general case to explain what I usually do manually.

我用3个标签(从这里指的是A,B和C)和我在一个2x2布局打开每个选项卡4个文件:

I use 3 tabs (referring from here on as A, B and C) and I open 4 files in each tab in a 2x2 layout:

bash:~$ cd ~/Workspace/
bash:~/Workspace$ vim A11.m
:vsplit A12.m
:hsplit A22.m
"move cursor to A12.m"
:hsplit A21.m
:tabedit B11.m
:vsplit B12.m
:hsplit B22.m
"move cursor to B12.m"
:hsplit B21.m
:tabedit C11.m
:vsplit C12.m
:hsplit C22.m
"move cursor to C12.m"
:hsplit C21.m

我想创建一个shell脚本到其中的文件名和位置(S)是硬$ C $的CD,这在执行时会做上述所有。任何人都可以建议我一个方法,它能够使这成为可能(如果可能的话)?在此先感谢!

What I would like to create is a shell script into which the file names and location(s) are hard-coded, which upon execution would do all the above. Can anyone suggest to me an approach which would make this possible (if possible at all)? Thanks in advance!

PS:在我的.vimrc我增加了一些配置,即:拆分打开新的文件下(而不是上方)当前文件和:VSPLIT打开新文件的权利(而不是向左)

ps: In my .vimrc I have added some configurations such that :split opens the new file beneath (instead of above) the current file and :vsplit opens the new file to the right (instead of to the left).

推荐答案

有至少有四种方法可以做到这一点:

There are at least four ways to do this:


vim -s <(echo $':vsplit A12.m\n:hsplit A22.m\n…')


  • vim -S <(echo $'vsplit A12.m\nhsplit A22.m\n…')
    

    这是类似于@romainl,但你自己创建脚本,不使用除了bash脚本本身的任何文件(可能也只是一个别名,或在历史上线)。它可以在bash使用HERE弦,他们更可读的:

    it is similar to what @romainl, but you create the script by yourself and do not use any file besides the bash script itself (can be as well just an alias or a line in history). It is possible to use HERE-strings in bash, they are more readable:

    vim -S <(cat <<<EOF
    vsplit A12.m
    hsplit A22.m
    …
    EOF
    )
    


  • vim -c 'vsplit A12.m | hsplit A22.m | …'
    

    您可以有多个它们按顺序运行,而不是更多的则10因此,你必须参加的命令在一个 -c -c 用吧。

    You can have multiple -c keys which are run in sequence, but not more then ten thus you have to join commands in one -c with bar.

    而不是一个bash脚本,用vim之一:

    Instead of a bash script use vim one:

    #!/usr/bin/vim -S
    vsplit A12.m
    hsplit A22.m
    …
    

    。然后你可以使用chmod + X 并运行像任何其他执行文件。 Vim的治疗#!作为只是为了这个原因注释的领导者。

    . Then you can chmod +x it and run like any other executed file. Vim treats #! as a comment leader just for that reason.

    这篇关于如何写一个bash脚本使用分裂和标签的Vim打开多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 10-17 00:00