]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(doc): mention using <script> instead of <sfile> in :autocmd
authorzeertzjq <zeertzjq@outlook.com>
Thu, 19 Jun 2025 17:40:51 +0000 (19:40 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 19 Jun 2025 17:40:51 +0000 (19:40 +0200)
fixes: #17569

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/autocmd.txt

index 204a9117c4b104efd0665af28668b1adc0a4fed5..d11cb1f1851c02868c9949d3fcb8783fc9e5b2fb 100644 (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