I want to return to the open file after I executed command with :terminal <command>
First off, I am using neovim
.
So to get to the situation, I want to improve: follow these steps :
- create a sample file with
nvim foo
- write some text, e.g.
hello you
and save:w
- in vim command mode, run
:terminal cat foo
Currently, what happens? I can see how the terminal returns my output hello you
.
My question is, how do I return to my file foo
?
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
Remark
I prefer :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.
update
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 :!q
like :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 windows
and:help terminal
for details on using:terminal
<c-w> h/j/k/l
or similar commands. Otherwise, you can close the terminal window with<c-\><c-n>:q!
(notice it's:q!
instead of:!q
), or better, with<c-w><c-c>
.: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 `:! <cmd>
<cr>
, ie.:tnoremap <Esc> <C-\><C-n>:q!<cr>
. Otherwise use<c-w><c-c>
. It's much neater too ---:tnoremap <Esc> <C-w><C-c>
.