Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open files in different split windows in VIM

Tags:

vim

vi

editor

I have some $somePaths array of 4 folders. I want to open some files from this folders in VIM. The following opens them in tabs.

vim -p `for i in ${somePaths[@];}; do echo $i/src/main.cpp; done`

Actually I'd like to have those files in split windows (cross-like). How it can be done?

like image 922
Loom Avatar asked Mar 28 '14 15:03

Loom


People also ask

How do I open two split screens in vim?

To split the vim screen horizontally, or open a new workspace at the bottom of the active selection, press Ctrl + w , followed by the letter 's' . In the example below, the left section has been split into two workspaces. To navigate to the bottom section hit Ctrl + w , followed by the letter 'j' .

How do I open multiple windows in vim?

To open a new VIM window next to the existing one, press <Ctrl>+<w> then press <v>. You can move to the left window again by pressing <Crtl>+<w> and then pressing <h>. To open a new VIM window on the bottom of the currently selected window, press <Ctrl>+<w> then press <s>.


3 Answers

Apart from -p, Vim also offers the -o and -O command-line arguments for horizontal / vertical splits. Unfortunately, they cannot be mixed. To build you own custom window layout, you have to pass the explicit window placement commands via -c. This example

 $ vim 1 -c 'bel vsplit 2' -c '1wincmd w' -c 'bel split 3' -c '3wincmd w' -c 'bel split 4'

creates a layout that looks like this:

+-----------+-----------+
|           |           |
|           |           |
|           |           |
|1          |2          |
+-----------+-----------+
|           |           |
|           |           |
|           |           |
|3          |4          |
+-----------+-----------+

To keep passing the list of files as one block, you can use the fact that the buffer numbers increase monotonically, and refer to buffer numbers in the command:

$ vim -c 'bel vert sbuf 2' -c '1wincmd w' -c 'bel sbuf 3' -c '3wincmd w' -c 'bel sbuf 4' a b c d
like image 90
Ingo Karkat Avatar answered Oct 17 '22 07:10

Ingo Karkat


vim has :vertical command, which could be useful in your case. give this a try:

vim +'vertical all' [your file list]
like image 28
Kent Avatar answered Oct 17 '22 08:10

Kent


You can try using -O4 instead of -p.

like image 3
Jeff Avatar answered Oct 17 '22 06:10

Jeff