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.
Here I summarize what I found,
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)
the application launched as expected, then you can press enter then it closes the window. All done.
Trial 1 - direct
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.
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.
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 -
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