首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每个‘`ftplugin/name.vim’都需要定义`b:undo_ftplugin`吗?

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

Stack Overflow用户
提问于 2012-07-11 05:12:02
回答 1查看 1.2K关注 0票数 8

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

当我set ft=python,然后set ft=css$VIMRUNTIME/ftplugin/css.vim立即完成。和omnifunc=pythoncomplete#Complete一直在一起。

是否每个ftplugin/name.vim都需要定义b:undo_ftplugin

我是/usr/share/vim/vim73/ftplugin.vim

代码语言:javascript
复制
" 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

代码语言:javascript
复制
" 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

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

代码语言:javascript
复制
if &cpo =~# "S" && exists("b:did_ftplugin")

b:did_ftplugin没有被删除,所以ftplugin/css.vim立即完成。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-11 06:36:54

:help undo_ftplugin提到:

当用户执行":setfiletype xyz“时,应该取消前一个文件类型的效果。

注意,它写的是“应该”,而不是“必须”。但是,根据执行情况

代码语言:javascript
复制
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 (如果只是一个空的、没有操作的值)。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11425906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档