Home

InsertEnter

InsertEnter is an autocommand event in Vim and Neovim that fires when the editor enters insert mode. It runs after the mode change to insert mode has occurred, and it does not trigger when entering other modes. The event is commonly used to apply or adjust settings that should only be active while typing, or to trigger plugin behavior as soon as you start inserting text. It has a counterpart, InsertLeave, which fires when you leave insert mode, and there is also InsertCharPre, which runs just before a character is inserted in insert mode.

Scope and usage

InsertEnter can be attached to with the :autocmd command, and its pattern can limit when it runs

Examples

Typical Vimscript usage:

autocmd InsertEnter * setlocal paste

autocmd InsertLeave * setlocal nopaste

Neovim users can also implement this in Lua, for example via the Neovim API:

vim.api.nvim_create_autocmd("InsertEnter", { pattern = "*", callback = function() vim.opt_local.paste = true end })

vim.api.nvim_create_autocmd("InsertLeave", { pattern = "*", callback = function() vim.opt_local.paste = false end })

Compatibility

InsertEnter is supported in Vim and Neovim as part of their autocommand and event systems. It is

(for
example,
by
filetype
or
filename).
It
can
be
combined
with
InsertLeave
to
restore
settings
when
you
exit
insert
mode,
or
with
InsertCharPre
for
fine-grained
control
over
typing
behavior.
Common
uses
include
toggling
paste
mode
on
entering
insert
mode
and
restoring
it
on
leaving,
or
logging
and
plugin
initialization
that
should
occur
only
while
typing.
a
standard
tool
for
automating
behavior
tied
to
entering
insert
mode.