views:

396

answers:

4

If, at a command prompt, I run

vimdiff file1 file2

I get a vim instance that has two files open side-by-side, something like this:

╔═══════╤═══════╗
║       │       ║
║       │       ║
║ file1 │ file2 ║
║       │       ║
║       │       ║
╚═══════╧═══════╝

This is very nice, but sometimes I want to open a third file to look at. I don't want to create another vertical split, because otherwise the lines will be so short I'd be scrolling horizontally all the time just to read them. But occupying a few lines at the bottom of the screen wouldn't hurt. So, how can I go from the above to the following:

╔═══════╤═══════╗
║       │       ║
║ file1 │ file2 ║
║       │       ║
╟───────┴───────╢
║     file3     ║
╚═══════════════╝

I've tried using :sp file3, but I just end up with this (supposing I ran the command while the cursor was in file1):

╔═══════╤═══════╗
║ file3 │       ║
║       │       ║
╟───────┤ file2 ║
║ file1 │       ║
║       │       ║
╚═══════╧═══════╝

Thanks in advance for your help!

+8  A: 

Use

:botright split

and open a new file inside.

fgm
+2  A: 

If you've already opened :sp file3 as in your last example ^WJ will move an existing window where you want it to go.

asparagino
+2  A: 

To expand on @fgm's answer, If you type this command, you can auto complete the file name you want to edit like in a normal :edit:

:bot split +edit thirdfile.cpp

But to avoid having to type all that, you can create a "User defined command" like this:

:command -complete=file -nargs=* Third bot split +edit <args>

Now you can just type :Third to create the third window at the bottom of the screen with the file you want to edit, for example:

:Third mythirdfile.cpp

Notice that you can auto complete just like with a normal :edit.

And of course you can change the name of the command to something else if you don't like :Third, just keep in mind that it must start with a capital letter.

For more info type :help user-commands and :help 40.2

Jorge Gajon
And of course, to have your defined command permanent, put it on your .vimrc file, leaving out the colon (:).
Jorge Gajon
A: 

I have question to go along with this one.

I am opening 3 windows using vimdiff.

I would like to have file3 be in edit mode, and file1 and file2 to be in read only mode.

Is this possible?

This is my command...

vimdiff -R file1 file2 -c :topleft sp file3

Thanks,

Tom

Tom