The main objective of this question is I want to get the shell command's execution result to show in small split window right inside vim while I'm editing the file; the same result I would get when I hook such shell commands to execute through autocmd. But thing is I want such result if I configure key binding with nnoremap, not though file events e.g. BufWritePost.

Here I summarize what I found,

My Objective

The following line inside .vimrc will achieve the final result I want but unfortunately, only file event can trigger.

" when write to main.cpp then execute make and run the final program called "overlay"
autocmd BufWritePost main.cpp   !make && ./overlay &

it will show the result of such commands in the small (kinda special, it's like message window with no buffer or anything) window at the bottom like this (Please excuse my tmux's tagline)

enter image description here

the application launched as expected, then you can press enter then it closes the window. All done.

Try with nnoremap

Trial 1 - direct nnoremap

I tried with the following

nnoremap ,lb :!make && ./overlay &<CR>

Then it will show the result in full screen terminal window (not inside vim), then you can press enter then it will go back to vim again.

enter image description here

Trial 2 - scratch buffer

It has the following setting(solution from Stackoverflow)

nnoremap ,lb :new<Bar>setlocal buftype=nofile bufhidden=hide noswapfile<Bar>:0r!make && ./overlay<CR>

The result I got is as follows.

enter image description here

A scratch buffer which will have result from execution of command. But I guess due to this specific case such that I execute with & (run in background), I have to close the application first then the result will be shown inside such scratch buffer. Then from there I can save the content, or close it.

PS: One thing I didn't do is specify the height of split window which is possible. But still for other elements, it is still not close enough.

Trial 3 - autocmd with nnoremap

I then try to use

autocmd FileType cpp,h,hpp nnoremap ,lb :!make && ./overlay &<CR>

with hope that if I hook up key binding with autocmd, it probably should show the same window I want to achieve as seen in My Objective.

But it turns out to have the same effect as of Trial 1.

As you can see, there's nothing similar or come really close (although Trial 2 is almost there) for what I would like to achieve as shown in My Objective.

So now recap the question: How could I achieve the same result as shown in My Objective running the shell commands through key mapping of nnoremap?

  • 2
    You may want to take a look at :make and read about the quickfix window which is designed for a workflow similar to yours. Apr 3, 2021 at 10:05
  • 1
    Also plugins Clam, Dispatch, and the integrated :terminal, possibly with a tool like entr
    – D. Ben Knoble
    Apr 3, 2021 at 13:54
  • I think you guys are right that at last it would be necessary to check the code. I noted both of your suggestions down for further research. Thank you very much.
    – haxpor
    Apr 4, 2021 at 8:13

2 Answers 2


What you're describing can be easily achieved with vim-altscreen.

Based on the screenshots in your post and the short description of what you want at the top of it, this seem to match what you seek.


As a slight workflow adjustment, I would use :make (or possibly :Make from the dispatch plugin) to build. Then I would run :terminal ./overlay & for the program part. This gives you a window running exactly that command. (There’s also :Dispatch, and maybe :Start/:Spawn, from the dispatch plugin. All are async when possible and come with foreground and background options.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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