Basicly I want the following functionality:
Using vims new terminal functionality, I want to be able to press a button, that opens a new terminal window, without stealing focus from the file I'm editing, that compiles my code using :
"cmake -Bbuild -H. && cmake --build build/ -- -j4 -w" that shows me the compilation live and just lets me close it again using another button when I don't need it anymore

So how can I execute a complex command using :terminal while leaving the focus in the original split?


As far as I know you cant right now. You can run one command (:ter command) or a shell (:ter), but cant put command into the open shell.
:ter cmake -Bbuild -H. && cmake --build build/ -- -j4 -w
will start the build but you have to go back to the other window with C-W w or C-W k or C-W j or C-W h or C-W l. Then you can continue to type while watching the build.
nmap < leader > b :ter cmake -Bbuild -H. && cmake --build build/ -- -j4 -w
Put this into your .vimrc. If you press leader then b it will start it. Default leader is \ if you did not change it yet.
You can do it with Tmux probably.

Edit: You can do it!
function! s:Buildit()
ter cmake -Bbuild -H. && cmake --build build/ -- -j4 -w
wincmd w
com! Buildit call s:Buildit()
nnoremap < leader > b :Buildit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.