从命令行使用vim split命令获得4个季度的分割


20

我想在命令行上打开四个vim文件:

vim file1 file2 file3

但是我希望每个文件都单独打开:

vim -c "split file1" -c "split file2" -c "split file3" file4

(以上将屏幕水平分割4次)

理想情况下,我想将屏幕分成4个正方形,例如:

|-------|-------|
|       |       |
|       |       |
|-------|-------|
|       |       |
|       |       |
|-------|-------|

打开vim后,我知道如何执行此操作,但是无法从命令行(使用vs)执行此操作。有任何想法吗?我尝试的一切最终都看起来像这样(或其他变体):

|-------|-------|
|       |       |
|-------|       |
|       |       |
|-------|       |
|       |       |
|       |       |
|-------|-------|

Answers:


22

您可以使用“ wincmd”命令移至其他窗口,就像按CTRL + W一样。

vim file4 -c 'split file2' -c 'vsplit file1' -c 'wincmd j' -c 'vsplit file3'

这会将文件排列为:

file1   file2
file3   file4

工作原理:打开file4。水平分割,使file2在其上方。垂直分割,因此file1在左侧,移至下一个窗口(file1),然后再次垂直分割。


7

我使用此信息编写了一个脚本,该脚本可以根据需要自动拆分屏幕:

vimsp.py file1 file2 / file3

结果是

-----------
|f1  |f2  |
|    |    |
-----------
|file 3   |
|         |
-----------

另外,将/放在所有文件的前面会使它们全部垂直分割:

vimsp.py / file1 file2 file3

-------------
|file 1     |
-------------
|file 2     |
-------------
|file 3     |
-------------

https://gist.github.com/1376956


1

严格从命令行:

vim -o3 <list of 9 files> -c:{vsp,vsp,wincmd\ j,vsp,vsp,wincmd\ j,vsp,vsp} \
  -c "windo execute 'argument ' . winnr()"

...将在3x3网格中打开9个文件。

您也可以编写一个函数并将其添加到您的.vimrc,类似于以下内容。希望有经验的vim脚本编写者可以考虑一下,因为我知道这是不正确的:

function! mysplit(...)
  execute sp #1
  execute sp #1
  execute vsp
  execute vsp
  execute wincmd j
  execute vsp
  execute vsp
  execute wincmd j
  execute vsp
  execute vsp
  % I'm not at all experienced with writing vim scripts, so
  % the syntax on the following line is almost certainly not
  % correct; this is conceptual only.
  execute windo execute 'argument ' . winnr()
endfunction

...然后从命令行使用它:

vim <list of 9 files> -c ':execute mysplit()'
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.