mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01: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
|
:au BufNewFile,BufRead *.html so <sfile>:h/html.vim
|
||||||
|
|
||||||
Here Vim expands <sfile> to the name of the file containing this line.
|
Here Vim expands <sfile> to the name of the file containing this line.
|
||||||
Use <script> instead to avoid that: >
|
However, <sfile> works differently in a function, in which case it's better to
|
||||||
|
use `:execute` with <script> to achieve the same purpose:
|
||||||
:au BufNewFile,BufRead *.html so <script>:h/html.vim
|
>
|
||||||
|
:exe $'au BufNewFile,BufRead *.html so {expand("<script>:h")}/html.vim'
|
||||||
|
|
||||||
`:autocmd` adds to the list of autocommands regardless of whether they are
|
`:autocmd` adds to the list of autocommands regardless of whether they are
|
||||||
already present. When your .vimrc file is sourced twice, the autocommands
|
already present. When your .vimrc file is sourced twice, the autocommands
|
||||||
@ -90,7 +91,7 @@ that you can easily clear them: >
|
|||||||
augroup vimrc
|
augroup vimrc
|
||||||
" Remove all vimrc autocommands
|
" Remove all vimrc autocommands
|
||||||
autocmd!
|
autocmd!
|
||||||
au BufNewFile,BufRead *.html so <script>:h/html.vim
|
au BufNewFile,BufRead *.html so <sfile>:h/html.vim
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
If you don't want to remove all autocommands, you can instead use a variable
|
If you don't want to remove all autocommands, you can instead use a variable
|
||||||
|
Reference in New Issue
Block a user