Home

WinEnter

WinEnter is an autocommand event in Vim and Neovim that fires when the focus switches to a different window. It is part of the window-related events that allow per-window customization as users navigate splits, tabs, or other window arrangements.

The event is typically used to adjust window-local options or apply context-specific behavior as the active

In Vimscript, you can attach actions to WinEnter with an autocmd. For example:

autocmd WinEnter * setlocal cursorline

autocmd WinEnter * setlocal number

In Neovim, the same can be written in Lua using the API:

vim.api.nvim_create_autocmd("WinEnter", { pattern = "*", callback = function()

vim.opt_local.number = true

end})

WinEnter is commonly used alongside WinLeave, BufWinEnter, and other window events to manage per-window state as

window
changes.
Common
uses
include
enabling
or
adjusting
cursorline,
line
numbers,
wrapping,
or
local
formatting
settings
when
entering
a
window.
It
can
be
combined
with
patterns
to
limit
its
scope
and
is
frequently
paired
with
WinLeave
for
symmetrical
behavior
when
leaving
a
window.
users
move
between
windows.
While
simple
demonstrations
enable
basic
options,
more
advanced
configurations
might
conditionally
apply
settings
based
on
file
type,
buffer
type,
or
specific
window
characteristics.