You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过命令行启动Vim并以垂直+水平分窗布局打开3个文件?

从命令行配置Vim指定分窗布局的最简方式

我经常需要打开三组相关文件,希望以如下分窗布局打开(光标默认在file1中):

,---------------------------,
| file1       | file2       |
| #cursor     |             |
|             |             |
|---------------------------|
| file3                     |
|                           |
|                           |
'---------------------------'

我已经实现了该布局,但想了解是否有更简便的命令行写法。当前实现方式如下:

vim \
  -O2 file1 file2 \
  -c ':split file3' \
  -c ':wincmd J' \
  -c ':wincmd t'

更简便的命令行写法

可以将多个-c参数合并为一个,利用Vim的命令分隔符|串联操作,减少参数数量,写法更简洁:

vim -O2 file1 file2 -c 'sp file3 | wincmd J | wincmd t'

补充说明

  • sp是split的简写,能进一步缩短命令长度
  • 如果需要频繁使用这个布局,还可以在~/.vimrc中定义自定义命令,进一步简化调用:
    command! -nargs=3 OpenTripleLayout :e <f-args> | vsp <f-args> | sp <f-args> | wincmd J | wincmd t
    
    之后在命令行只需执行:
    vim -c 'OpenTripleLayout file1 file2 file3'
    

内容的提问来源于stack exchange,提问作者meleu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 18:12:22