puk
puk

Reputation: 16752

Set Vim window size and selection from command line

I want to launch two files from the command line and I want the window to be split horizontally. This can be achieved with the following command:

vim -o index.html index.1

Which gives me the following output split evenly

enter image description here

What I want, instead, is for the top window to be substantially larger, like so

enter image description here

How do I achieve this? Also, currently, the top window is selected, which is what I want. However, if it wasn't selected, or I wanted the bottom window selected, how would I go about achieving this?

Upvotes: 2

Views: 908

Answers (2)

mhinz
mhinz

Reputation: 3351

One possible solution would be to make the top window 80% of the available size:

vim +'execute "resize" (&lines / 10) * 8' -o file1 file2

See :help :resize and :help 'lines' for more information.

Small clarification: & is used in front of options to retrieve its value. Thus &lines holds the value of what you could set yourself, e.g.:set lines=100. In this case, &lines gets set by Vim on-the-fly even when you resize the window that holds Vim.

Upvotes: 1

user1146332
user1146332

Reputation: 2770

You can open the two files with

vim index.html +10sp index.1

After vim has read index.html it executes the ex command 10sp. That means that the current window is split into two with the new window being 10 rows high. After that index.1 is read by vim and loaded into the currently active window.

If you already set splitbelow in your .vimrc index.1 is loaded into the bottom window that is active at the same time.

For example if you want the top window to be active and splitbelow is set you can append the corresponding ex command to the line

vim index.html +10sp index.1 +"wincmd k"

Upvotes: 1

Related Questions