-
Notifications
You must be signed in to change notification settings - Fork 4
Autocmds
Kyler Clay edited this page Aug 24, 2026
·
2 revisions
The autocmd builtin registers shell commands to run on specific events. Many events expose context variables that autocmds can use for conditional logic.
Examples:
autocmd on-exit 'echo goodbye'
autocmd post-change-dir 'msg "moved to $NEW_DIR"' # dispatch a status message on directory change
autocmd on-time-report 'echo $TIME_CMD took $TIME_REAL_FMT' # executes after the 'time' builtin returnsAvailable events:
| Event | When it fires |
|---|---|
pre-cmd, post-cmd
|
Before/after command execution |
pre-change-dir, post-change-dir
|
Before/after cwd changes |
pre-prompt, post-prompt
|
Before/after prompt display |
pre-mode-change, post-mode-change
|
Before/after editor mode switch |
on-history-open, on-history-close, on-history-select
|
History search events |
on-completion-start, on-completion-cancel, on-completion-select
|
Tab completion events |
on-job-finish |
Background job completes |
on-time-report |
time-prefixed command completes |
on-command-not-found |
Command name can't be resolved |
on-idle-timeout |
Prompt idle past the idle timeout |
on-exit |
Shell is exiting |
Use -c to clear all autocmds for an event. Context variables are scoped to the autocmd command and documented in help autocmd. Passing only the event name to autocmd will list all registered commands for that event.