1

Is there a proper way to exit nterm ?

My current solution is to enter from nterm to the terminal with i and then c-d.

3
  • Do you still have something open in your question? Otherwise may be could you accept one of the answers using the v button next to the arrow voting buttons. It allow the question to rest :-) and let others know that the answer is worth reading ;-) Feb 2 at 6:07
  • Yes, of curse. I just wasn't sure because of the <c-s-q> Mapping... Thx, for the help :D Feb 3 at 16:33
  • Thanks for the feedback :-) Feb 3 at 16:38

1 Answer 1

1

If you are in Normal mode you can do :q or simply ZZ as for a normal window.

If you are in Terminal mode you can switch to Normal mode with Ctrl \Ctrl n and then :q or ZZ

To simplify that you can add a Terminal mapping to Ctrl q:

tnoremap <C-q> <C-\><C-n>

Or in Lua:

vim.api.nvim_set_keymap("t", "<C-q>", "<C-\\><C-n>", {noremap = true})

You can combine both in one:

tnoremap <C-S-q> <C-\><C-n>ZZ

Or in Lua:

vim.api.nvim_set_keymap("t", "<C-S-q>", "<C-\\><C-n>ZZ", {noremap = true})

Vim/Neovim quit when the last window is closed.

A solution is then to:

  • Switch back to the terminal window
  • Close the terminal buffer
tnoremap <C-q> <C-\><C-n>:bd!<CR>

Or in Lua:

vim.api.nvim_set_keymap("t", "<C-q>", "<C-\\><C-n>:bd!<CR>", {noremap = true})
10
  • Thx, for the shortcuts :D I had a problem with <C-\> should i escape it ? I really would like to go from nterm/:term to normal mode without closing vim... And it seems that they are all closing vim... Jan 31 at 11:03
  • When you are closing the last window Vim close. To avoid that you have to create another window before closing the one with the terminal. The new <C-S-q> mapping in terminal mode does that (leave Terminal mode, create a new window, close the terminal window) Jan 31 at 12:26
  • 1
    You need to escape the \ if you write your mapping in Lua. I believe the answer to your question the terminal buffer is not a normal editing buffer. You can't switch it to a "normal" buffer. Jan 31 at 14:01
  • 1
    Thats what i ment with :q When i open nvim with no filename , write some text, make a new buffer which is empty, then i write :q, it will close new generated Buffer. Now I'm Back where i started "1st" buffer. Now when generate a new buffer, write text, save file with filename and now i press :q it will NOT close current Buffer and go to "1st" Buffer. When i now save this buffer with filename then press :q it will quit all Buffers... But if you open nvim go straigth to a terminal session make new Buffer then press :q it quits all. These are all different behaviours. That's what confused me. Jan 31 at 21:14
  • 1
    I have found a simpler way to get closer to the <C-d><space> experience. I have updated the solution accordingly :-) Let me know if it solves your problem ;-) Feb 1 at 7:29

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.