3

As title. I need to use this in a script to close the current floating window.

2
  • 1
    Probably with feedkeys()?
    – D. Ben Knoble
    Jan 18, 2022 at 1:43
  • @D.BenKnoble Just realized that nvim_feedkeys is blocking and thus preferred in my use case (by hitting my foot with nvim_input). (late) Thanks for you kindly comment. Jun 20, 2022 at 22:21

3 Answers 3

1

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)
0
1

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.

0

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

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.