I want to return to the open file after I executed command with
First off, I am using
So to get to the situation, I want to improve: follow these steps :
- create a sample file with
- write some text, e.g.
hello youand save
- in vim command mode, run
:terminal cat foo
Currently, what happens? I can see how the terminal returns my output
My question is, how do I return to my file
When I type
:q I quit vim. Then I could run
:e foo, but I prefer a more elegant solution. Since when I run
:! cat foo I get
:! cat foo Hello you Press ENTER or type command to continue
So that a simple
enter returns me to my file. Is there a similar way to do this with
:terminal since it has the terminal colors which help in reading longer test results. Surely, I am using the
cat command just as an example.
After some digging in the documentation link. I found that the terminal has its own mapping so that I can change the
esc key to get into command mode with
:tnoremap <Esc> <C-\><C-n>
I assumed that just adding
:tnoremap <Esc> <C-\><C-n>:!q would quit but that does not work.
But when using
:tnoremap <Esc> <C-\><C-n> in the command I type
:!q I get
E37: No write since last change E162: No write since last change for buffer "[No Name]" Press ENTER or type command to continue
That means I only need to add force stop into shortcut Does anybody know how to do that?
<c-w>p? Maybe I don't fully understand your question... but do you really need to close the terminal window?
:help terminalfor details on using
<c-w> h/j/k/lor similar commands. Otherwise, you can close the terminal window with
:!q), or better, with
:tnoremap <Esc> <C-\><C-n>:q!and it did not close on <kbd>esc<\kbd>. Well I just want to reproduce the behaviour of from
:terminal <cmd>similar to `
:tnoremap <Esc> <C-\><C-n>:q!<cr>. Otherwise use
<c-w><c-c>. It's much neater too ---
:tnoremap <Esc> <C-w><C-c>.