I would like to have commands like :ce and :ctabe that open a tab with a vertical split with the .c file on one site and the corresponding .h file on the other. How can i accomplish this behaviour?
-
1If you search this site for “custom command” there are lots of examples. Then it’s a matter of figuring out the commands to open the appropriate files. As it stands, your question is a little unclear and could use some additional detail to define the problem and what a good solution looks like– D. Ben Knoble ♦Nov 4, 2018 at 19:58
1 Answer
Custom commands cannot start with lowercase letters, but you can define for example :Ce
and :Ctabe
.
Here's a custom function that does the same as :edit {file}
:
command! -nargs=1 -complete=file Ce edit <args>
In order to open another related file, you would use :vsplit
; the current file can be referenced via the :help cmdline-special
notation %
. %:r
gives you the current file without its file extension. So the following will open the corresponding header file:
command! -nargs=1 -complete=file Ce edit <args> | vsplit %:r.h
PS: There are several plugins that do something like that, too. A very old one is a.vim. A modern one is projectionist.vim.