0

I'd like to have to same remap to open and close my terminal.
Here is my remap to open it : nnoremap <C-s> :bel vert term<CR>
What I want is that when my terminal is already open, if I type <C-s> again, it execute exit<CR>
I already tried a function that I found here : Toggle function in vim

let s:enable = 0
function! ToggleEasyMode()
    if s:enable
        nnoremap <C-s> exit<CR>
        let s:enable = 0
    else
        nnoremap <C-s> :bel vert term<CR>
        let s:enable = 0
    endif
endfunction
romainl
  • 186,200
  • 21
  • 280
  • 313
Cyprien
  • 94
  • 7
  • 1
    Maybe you should be using `tnoremap` for terminal bindings? – Christian Gibbons Apr 29 '21 at 21:14
  • 3
    Unrequested useful information: this is not a "remap(ping)" but a *map(ping)*. Core Vim doesn't come with any mapping so there is nothing to "remap". The confusion may be caused by the "re" in "nnoremap" which is part of "nore", not of an imaginary "remap": `nnoremap` is made of `n` for "normal mode", `nore` for "non-recursive", `map` for… "map (this to that)". – romainl Apr 30 '21 at 06:55

1 Answers1

1

thanks to @ChristianGibbons
the answer:

nnoremap <C-s> :bel vert term<CR>
tnoremap <C-s> <CR>exit<CR>
Cyprien
  • 94
  • 7