Home

autocmd

An autocmd, short for auto-command, is a feature of Vim and Neovim that runs a specified command automatically when a defined event occurs, such as opening a file, entering a buffer, or writing a buffer. Autocommands let users tailor editor behavior without manual invocation.

Autocommands are defined with the syntax: autocmd {event} {pattern} {command}. Events include BufRead, BufNewFile, BufEnter, BufWritePost,

To organize and manage them, autocommands are typically placed inside augroups. Use augroup Name to start a

Common examples:

- autocmd BufReadPost *.md setlocal textwidth=80

- autocmd FileType python setlocal expandtab shiftwidth=4

- autocmd BufNewFile,BufReadPost *.log setlocal nospell

Viewing and learning more: :autocmd lists active autocommands, and :help autocmd opens detailed documentation. Good practice

FileType,
VimEnter,
WinEnter,
and
many
others.
The
pattern
matches
file
names,
buffer
names,
or
other
context;
wildcards
like
*
can
restrict
where
the
command
applies.
Additional
qualifiers
can
refine
behavior,
such
as
FileType
to
react
to
a
certain
language.
block,
autocmd!
to
clear
existing
commands
in
that
group,
add
individual
autocmd
lines,
and
end
with
augroup
END.
The
++once
modifier
can
make
a
specific
autocmd
run
only
once
for
its
event.
is
to
group
autocommands
with
augroup
and
avoid
unnecessary
work
during
startup
to
minimize
performance
impact.