jzimmerman
jzimmerman

Reputation: 74

Vim, custom tab and vertical split organization on open

Say the files in my working directory are src/example.c src/second.c src/third.c include/example.h include/second.h include/third.h.

I want to open vim in a way that automatically opens three tabs (example, second and third), where each tab contains a vertical split screen between a .c and corresponding .h file. Like the following commands would.

:tabnew include/example.h | vs src/example.c
:tabnew include/second.h | vs src/second.c
:tabnew include/third.h | vs src/third.c

Is there a way I can make a special script that will do this when I open vim?

It is safe to assume files will have the same name.

Ideally, this would happen from a shell script rather than modifying my .vimrc, if that is possible.

Upvotes: 0

Views: 170

Answers (1)

B.G.
B.G.

Reputation: 6026

well if you want to do that, you clearly need a way to execute vim commands from your shell. Lets see if the vim application supplies that, by using the help command which we should ask first for every shell command:

?> vim --help | grep cmd

--cmd <cmd>           Execute <cmd> before any config
+<cmd>, -c <cmd>      Execute <cmd> after config and first file

So all that is needed is to chain these commands:

vim -c 'tabnew include/example.h' -c 'vs src/example.c' -c 'tabnew include/second.h' -c 'vs src/second.c' -c 'tabnew include/third.h' -c 'vs src/third.c'

as @Enlico pointed out in the comment, you should use edit or e instead of tabnew in the first command, else you will get 4 tabs. But I used your commands so you can see how easily you would have been able to solve this by reading the --help output.

Upvotes: 3

Related Questions