Home

InsertLeave

InsertLeave is an autocommand event in Vim and Neovim that fires when the editor switches from Insert mode back to Normal mode. It provides a hook for running commands or functions immediately after the user finishes inserting text.

The event is used in configuration and scripting to perform actions that should occur after editing pauses.

A typical practical use is to toggle settings that should be different while typing. For example, many

autocmd InsertEnter * set paste

autocmd InsertLeave * set nopaste

Related autocommand events include InsertEnter, which fires when entering Insert mode, and other editing-related events such

Common
uses
include
restoring
options
changed
during
insert,
such
as
turning
off
paste
mode,
updating
the
status
line,
or
triggering
a
formatting
or
cleanup
routine.
Because
Insert
mode
is
focused
on
input,
InsertLeave
offers
a
convenient
point
to
apply
post-edit
behavior
without
affecting
ongoing
typing.
users
enable
paste
mode
when
entering
Insert
mode
and
disable
it
when
leaving
Insert
mode
to
return
to
normal
editing
behavior.
A
common
Vimscript
pattern
is
to
pair
InsertEnter
with
InsertLeave
in
autocommands:
as
TextChangedI
and
TextChangedP.
InsertLeave
is
supported
in
both
Vim
and
Neovim
and
has
remained
a
stable
mechanism
for
scripting
editor
behavior
related
to
mode
transitions.