vim-patch:476b65e: runtime(doc): mention using <script> instead of <sfile> in :autocmd (#34580)

fixes: vim/vim#17569

476b65ebac
This commit is contained in:
zeertzjq
2025-06-20 07:08:01 +08:00
committed by GitHub
parent 528381587b
commit 927dc3c2c4

View File

@ -78,9 +78,10 @@ exception is that "<sfile>" is expanded when the autocmd is defined. Example:
:au BufNewFile,BufRead *.html so <sfile>:h/html.vim
Here Vim expands <sfile> to the name of the file containing this line.
Use <script> instead to avoid that: >
:au BufNewFile,BufRead *.html so <script>:h/html.vim
However, <sfile> works differently in a function, in which case it's better to
use `:execute` with <script> to achieve the same purpose:
>
:exe $'au BufNewFile,BufRead *.html so {expand("<script>:h")}/html.vim'
`:autocmd` adds to the list of autocommands regardless of whether they are
already present. When your .vimrc file is sourced twice, the autocommands
@ -90,7 +91,7 @@ that you can easily clear them: >
augroup vimrc
" Remove all vimrc autocommands
autocmd!
au BufNewFile,BufRead *.html so <script>:h/html.vim
au BufNewFile,BufRead *.html so <sfile>:h/html.vim
augroup END
If you don't want to remove all autocommands, you can instead use a variable