As title. I need to use this in a script to close the current floating window.
3 Answers
I just resolved this using NeoVIm by the way:
vim.keymap.set({'n', 't'}, '<M-Tab>', function ()
if (vim.api.nvim_win_get_config(0).relative ~= '') then
vim.api.nvim_input('<ESC>')
end
require('FTerm').toggle()
end, NOREF_NOERR_TRUNC)
In my case I spent a lot of time trying to go back to terminal-normal mode, and this works:
vim.api.nvim_feedkeys('', 't', true)
The invisible part in neovim looks like ^\^N
. And to make it work as expected you need to make sure that you don't do any "smart" remapping on neither <C-N>
nor <C-\\>
in Tmux or Alacritty configs. (I did :()
So to my original question <Esc>
looks like ^[
, but in one (not two!) char.
There is also :stopinsert
, which "works like typing <Esc>
in Insert mode."
*:stopi* *:stopinsert*
:stopi[nsert] Stop Insert mode or |Terminal-mode| as soon as
possible. Works like typing <Esc> in Insert mode.
Can be used in an autocommand, example:
:au BufEnter scratch stopinsert
feedkeys()
?nvim_feedkeys
is blocking and thus preferred in my use case (by hitting my foot withnvim_input
). (late) Thanks for you kindly comment.