mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
vim-patch:476b65e: runtime(doc): mention using <script> instead of <sfile> in :autocmd (#34580)
fixes: vim/vim#17569
476b65ebac
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user