1
0
forked from aniani/vim

runtime(doc): mention using <script> instead of <sfile> in :autocmd

fixes: #17569

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq 2025-06-19 19:40:51 +02:00 committed by Christian Brabandt
parent c50f4d07c4
commit 476b65ebac
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -1,4 +1,4 @@
*autocmd.txt* For Vim version 9.1. Last change: 2025 Apr 21
*autocmd.txt* For Vim version 9.1. Last change: 2025 Jun 19
VIM REFERENCE MANUAL by Bram Moolenaar
@ -130,6 +130,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.
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