How does

autocmd FocusLost * call feedkeys("\<esc>") (back to normal mode, if focus is lost)

translate to lua in init.lua?

1 Answer 1


I believe you should do:

vim.api.nvim_create_autocmd("FocusLost", { pattern = "*", command = [[call feedkeys("\<esc>")]] })

More information with: :help nvim_create_autocmd()

  • Indeed, thank you :-) ! Apr 26, 2023 at 19:13
  • Thanks for the feedback! If the solution fit your need maybe could you validate it using the v button next to the arrow voting buttons. It allow the question to rest :-) Apr 26, 2023 at 19:14

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.