首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Autocmd似乎没有触发金鸡。

Autocmd似乎没有触发金鸡。
EN

Stack Overflow用户
提问于 2014-03-12 17:01:57
回答 1查看 144关注 0票数 0

我的vimrc中有以下几行

代码语言:javascript
复制
" Python indenting and folding
au! FileType python set foldmethod=indent
au! FileType python set nosmartindent

" C++ indenting and folding
au! FileType cpp set cino=i-s
au! FileType cpp set cinkeys=0{,0},0),:,!^F,o,O,e
au! FileType cpp set cinkeys-=0#
au! FileType cpp set smartindent
au! FileType cpp set foldmethod=syntax

fu! FUNC_ECHOVAR(varname)
  :let varstr=a:varname
  :exec 'let g:foo = &'.varstr
  :echo varstr.' = '.g:foo
endfu
command! -nargs=1 ECHOVAR :call FUNC_ECHOVAR(<f-args>)


func! MYINFO()
    :ECHOVAR cino
    :ECHOVAR cinkeys
    :ECHOVAR foldmethod
    :ECHOVAR filetype
    :ECHOVAR smartindent
endfu
command! MYINFOCMD call MYINFO() <C-R>

当我打开一个C++文件并执行MYINFOCMD命令时,我会看到以下打印输出

代码语言:javascript
复制
cino = {1s
cinkeys = 0{0,},),:,0#,!^F,o,O,e
foldmethod = syntax
filetype = cpp
smartindent = 0

我不明白为什么autocmd FileType cpp没有正确设置这些变量,或者至少没有按照我预期的方式设置这些变量。

有人知道我为什么要这样吗!当我加载.cpp文件时,命令不会触发吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-12 22:16:56

对每个自动命令事件和模式最多使用一次:au!,因为它删除了以前定义的自动命令。(如果您的vimrc文件多次获得sourced,则使用它,这样自动命令就不会重复。)来自:help autocmd-remove

代码语言:javascript
复制
:au[tocmd]! [group] {event} {pat} [nested] {cmd}
            Remove all autocommands associated with {event} and
            {pat}, and add the command {cmd}.  See
            |autocmd-nested| for [nested].

或者,将所有的自动命令放在一个组中,只使用一次:au! (:help autocmd-groups):

代码语言:javascript
复制
augroup Erotemic
  au!
  " Python indenting and folding
  au FileType python set foldmethod=indent
  au FileType python set nosmartindent

  " C++ indenting and folding
  au FileType cpp set cino=i-s
  au FileType cpp set cinkeys=0{,0},0),:,!^F,o,O,e
  au FileType cpp set cinkeys-=0#
  au FileType cpp set smartindent
  au FileType cpp set foldmethod=syntax
augroup END

下面是当我尝试您的自动命令行的前两行,然后列出每个行之后的FileType python自动命令时会发生的情况:

代码语言:javascript
复制
:au! FileType python set foldmethod=indent
:au FileType python

--- Auto-Commands ---
FileType
    python    set foldmethod=indent

:au! FileType python set nosmartindent
:au FileType python

--- Auto-Commands ---
FileType
    python    set nosmartindent
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22358720

复制
相关文章

相似问题

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