以下是来自 vim 插件的 vim 脚本:
vim 的语法有点奇怪:
!exists("*s:SetVals")
,为什么他们之前是一个starmark s:
? !
特点? &iskeyword
,这是一个变量,如果是,它是在哪里定义的? s:
和 g:
,它们之间有什么区别? let &dictionary = g:pydiction_location
,我可以把它改成&dictionary = g:pydiction_location
吗? ? if !exists("*s:SetVals")
function! s:SetVals() " Save and change any config values we need. " Temporarily change isk to treat periods and opening " parenthesis as part of a keyword -- so we can complete " python modules and functions: let s:pydiction_save_isk = &iskeyword setlocal iskeyword +=.,( " Save any current dictionaries the user has set: let s:pydiction_save_dictions = &dictionary " Temporarily use only pydiction's dictionary: let &dictionary = g:pydiction_location " Save the ins-completion options the user has set: let s:pydiction_save_cot = &completeopt " Have the completion menu show up for one or more matches: let &completeopt = "menu,menuone" " Set the popup menu height: let s:pydiction_save_pumheight = &pumheight if !exists('g:pydiction_menu_height') let g:pydiction_menu_height = 15 endif let &pumheight = g:pydiction_menu_height return '' endfunction
endif
最佳答案
1.
!exists("*s:SetVals")
, why their is a starmark before s:?
星号是exists 函数的特殊语法,它意味着我们正在检查是否存在名为SetVals 的现有函数。选项
iskeyword
可以通过 exists("&iskeyword")
检查和 ex 命令 echo
与 exists(":echo")
见
:h exists(
2.
function!
, why there is a ! character?
感叹号表示如果函数已经存在,则将被替换。
见
:h user-functions
3.
&iskeyword
, is this a variable, if yes, where it is defined?
那是一个 vim 选项。您可以检查它是否设置为
:set iskeyword?
4. what is
s:
andg:
, what is the difference between them?
这些定义了以下符号的范围。
s:
表示符号是脚本的本地符号,而 g:
意味着符号将是全局的。见
:h internal-variables
和 s:
见 :h script-variable
5. why
let
should be used? such aslet &dictionary = g:pydiction_location, can i change it to be &dictionary = g:pydiction_location
?
Vimscript 是一种需要用关键字声明变量的语言。我认为没有比
let
更容易声明变量的方法了。 .
关于editor - 如何理解这个vim脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12625091/