How do I find which script defined my BufWritePre autocommands?
:verbose autocmd BufWritePre
When a save hook starts behaving unexpectedly, the hard part is usually finding who defined it.
:verbose autocmd BufWritePre
When a save hook starts behaving unexpectedly, the hard part is usually finding who defined it.
vim.api.nvim_create_autocmd('LspAttach', ...)
Setting your LSP keymaps inside a LspAttach autocmd ensures they are only active in buffers where a language server is actually running.
:set updatetime=300
Vim's updatetime option controls two things: how quickly the swap file is written after you stop typing, and how many milliseconds of inactivity before the Curs
autocmd BufNewFile *.py 0r ~/.vim/templates/python.py
When you create a new file in Vim (e.
:set commentstring=//\ %s
The commentstring option controls the template Vim uses to represent commented-out lines.
autocmd ++once
The ++once flag, added in Vim 8.
autocmd BufWinLeave * mkview
By default, Vim forgets your folds, cursor position, and scroll state every time you close a file.
:doautocmd FileType
When you change a buffer's filetype mid-session — say with :set filetype=python — Vim updates the filetype option but does not automatically re-run the File
augroup MyGroup | autocmd! | augroup END
Every time you run :source $MYVIMRC or :source % to reload your config, any bare autocmd calls are appended to Vim's autocommand table — no checking for dupli
:autocmd WinResized * wincmd =
When you resize your terminal window, Vim's split layout can become unbalanced.
:doautocmd User MyEvent
Vim's User event type lets you define custom events that fire on demand.
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
Vim remembers the last cursor position for every file you edit (stored in the viminfo or shada file), but by default it opens files at line 1.
autocmd FileType {lang} setlocal {options}
Vim's autocmd FileType lets you apply settings that only take effect when editing a specific file type.
autocmd BufWritePre * :%s/\s\+$//e
By adding an autocmd for the BufWritePre event, you can make Vim automatically strip trailing whitespace from every line each time you save.