gpt4 book ai didi

vim - 每个 `ftplugin/name.vim` 都需要定义 `b:undo_ftplugin` 吗?

转载 作者:行者123 更新时间:2023-12-02 07:55:47 25 4
gpt4 key购买 nike

$VIMRUNTIME/ftplugin/ 中的某些脚本(例如 python.vimada.vim)未定义 b:undo_ftplugincpo 选项默认值为 aABceFs

当我设置ft=python时,然后设置ft=css$VIMRUNTIME/ftplugin/css.vim 立即完成。并且始终omnifunc=pythoncomplete#Complete

每个ftplugin/name.vim都需要定义b:undo_ftplugin吗?

<小时/>

这是/usr/share/vim/vim73/ftplugin.vim:

" Vim support file to switch on loading plugins for file types
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2006 Apr 30

if exists("did_load_ftplugin")
finish
endif
let did_load_ftplugin = 1

augroup filetypeplugin
au FileType * call s:LoadFTPlugin()

func! s:LoadFTPlugin()
if exists("b:undo_ftplugin")
exe b:undo_ftplugin
unlet! b:undo_ftplugin b:did_ftplugin
endif

let s = expand("<amatch>")
if s != ""
if &cpo =~# "S" && exists("b:did_ftplugin")
" In compatible mode options are reset to the global values, need to
" set the local values also when a plugin was already used.
unlet b:did_ftplugin
endif

" When there is a dot it is used to separate filetype names. Thus for
" "aaa.bbb" load "aaa" and then "bbb".
for name in split(s, '\.')
exe 'runtime! ftplugin/' . name . '.vim ftplugin/' . name . '_*.vim ftplugin/' . name . '/*.vim'
endfor
endif
endfunc
augroup END

这是/usr/share/vim/vim73/ftplugin/css.vim:

" Vim filetype plugin file
" Language: CSS
" Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2008-07-09

if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1

let s:cpo_save = &cpo
set cpo&vim

let b:undo_ftplugin = "setl com< cms< inc< fo< ofu<"

setlocal comments=s1:/*,mb:*,ex:*/ commentstring&
setlocal formatoptions-=t formatoptions+=croql
setlocal omnifunc=csscomplete#CompleteCSS

let &l:include = '^\s*@import\s\+\%(url(\)\='

let &cpo = s:cpo_save
unlet s:cpo_save
<小时/>

如果我设置ft=python,那么设置ft=css。 Vim 无法通过此测试:

if &cpo =~# "S" && exists("b:did_ftplugin")

b:did_ftplugin 不会被删除,因此 ftplugin/css.vim 立即完成。

最佳答案

:help undo_ftplugin 提到:

When the user does ":setfiletype xyz" the effect of the previous filetype should be undone.

请注意,它说的是“应该”,而不是“必须”。但是,根据实现

func! s:LoadFTPlugin()
if exists("b:undo_ftplugin")
exe b:undo_ftplugin
unlet! b:undo_ftplugin b:did_ftplugin
endif

ftplugin 必须定义 b:undo_ftplugin,否则无法通过 :setf 更改其文件类型设置。我认为文档应该指出这一点,并且所有 ftplugins 确实应该设置 b:undo_ftplugin (如果只是一个空的、无操作的值)。

关于vim - 每个 `ftplugin/name.vim` 都需要定义 `b:undo_ftplugin` 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11425906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com