您可以将这些配置放在自定义脚本文件中,然后可选择使用该脚本文件打开您的工作区配置。
脚本文件:
:bl
:bf
:tabe
:n
:split
:vsplit
:wincmd l
:n
:wincmd j
:n
:n
:vsplit
:wincmd l
:n
:wincmd h
:wincmd k
:tabn
你可以这样称呼它:
vim -S script.vim file1.txt file2.txt file3.txt file4.txt file5.txt
根据您的配置,这将在 file1.txt 上打开 vim,旁边有一个打开的选项卡,并在切换到它时将光标放在左上角的文件 (file2.txt) 上。
增加了对每一行的解释:
请注意,当我们拆分时,光标将停留在原始窗口上,并且每个窗口将显示不同的文件,可以使用:n
和独立导航:N
。创建新窗口时,它将显示与我们创建窗口时所在的窗口相同的文件。
正如我在评论中提到的,前两行是告诉 VIM 我们已经阅读了每个文件,所以 VIM 不会在会话结束时抱怨“还有 4 个文件要编辑”。
:bl Go to last file
:bf Go to first file
:tabe Create new tab
:n Open next file (file2.txt)
:split Split horizontally (will create new window below with the content of file2.txt)
:vsplit Split vertically (will create new window on the top right with the content of file2.txt)
:wincmd l Go to the window to the right (which currently displays file2.txt)
:n Open next file (file3.txt)
:wincmd j Go to window at the bottom
:n Open next file (file3.txt, because bottom window was displaying file2.txt)
:n Open next file (file4.txt)
:vsplit Split vertically (will create new window on the right with content file4.txt)
:wincmd l Go to window to the right (which is bottom right)
:n Open next file (file5.txt, because bottom-right window was displaying file4.txt)
:wincmd h Go to window to the left
:wincmd k Go to window above (this sets the cursor on file2.txt on top left)
:tabn Go to next tab (the first one, displaying file1.txt)