Reputation: 21
I want to open multiple .cpp .h files in pair with tabe
and sp
commands. Suppose the current workplace has a.h, a.cpp, b.h, b.cpp, ... z.h, z.cpp.
I tried the following:
vim a.cpp -c 'sp a.h' -c 'tabe b.cpp' -c 'sp b.h' -c 'tabe c.cpp' -c 'sp c.h' -c 'tabe d.cpp' -c 'sp d.h' -c 'tabe e.cpp' -c 'sp e.h' -c 'tabe f.cpp'
which will work. However, the number of -c
commands is limited to 10.
So if want open more than 12 files, it will fail.
vim a.cpp -c 'sp a.h' -c 'tabe b.cpp' -c 'sp b.h' -c 'tabe c.cpp' -c 'sp c.h' -c 'tabe d.cpp' -c 'sp d.h' -c 'tabe e.cpp' -c 'sp e.h' -c 'tabe f.cpp' -c 'sp f.h' ...
will fail.
Is there a way to make this work?
Upvotes: 1
Views: 242
Reputation: 31419
You can use |
to separate command in vim. So you can combine all of your -c
into one command and pass that to -c
vim a.cpp -c 'sp a.h | tabe b.cpp | sp b.h | tabe c.cpp | ...'
Assuming you were in a folder with all the cpp and header files you could just run
vim -p *.cpp -c 'tabdo sp %<.h'
to simply everything. -p
tells vim to open all the files in tabs. So for every cpp file in the directory you will have one tab. After vim is loaded it will then run sp %<.h
in each of the tabs. Where
%<.h
is the original filename with the extension change to .h
. (%<
is the filename without extension. Take a look at :help %<
)
Vim defaults to only having 10 tab pages. If you need to open more than that you need to increase the tabpagemax
value.
set tabpagemax=100
Take a look at :help tabpagemax
(If you need this many tab pages I would recommend learning how to use buffers)
Upvotes: 4