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?
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' .
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>.
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
vim has :vertical
command, which could be useful in your case. give this a try:
vim +'vertical all' [your file list]
You can try using -O4
instead of -p
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With