editor - 如何理解这个vim脚本?

标签 editor vim

以下是来自 vim 插件的 vim 脚本:
vim 的语法有点奇怪:

  • !exists("*s:SetVals") ,为什么他们之前是一个starmark s: ?
  • 功能!,为什么会有!特点?
  • &iskeyword ,这是一个变量,如果是,它是在哪里定义的?
  • 什么是s:g: ,它们之间有什么区别?
  • 为什么要使用 let ?如 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 命令 echoexists(":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: and g:, what is the difference between them?



    这些定义了以下符号的范围。 s:表示符号是脚本的本地符号,而 g:意味着符号将是全局的。

    :h internal-variabless::h script-variable

    5. why let should be used? such as let &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/

    相关文章:

    function - 为什么我的 .vimrc 中的函数被自动调用?

    java - 打开类定义时禁用包资源管理器导航功能 (Eclipse)

    vim - 在 Vim 中,如何根据当前文件的扩展名显示或隐藏行号?

    android - 将方法字体颜色更改回原来的颜色(来自 Android Studio 更新)

    java - 如何阻止 Eclipse 移动光标以关闭 java 括号?

    firefox - 在 Mozilla Firefox 样式编辑器中退出 vim 插入模式

    vim - 怎样才能让 Vim tabularize 自动中断给定的列宽?

    python - 如何执行 python 脚本并保持打开的 shell 以便在 VIM 中进行进一步测试

    c++11 - 如何禁用 vim 粘贴到/从系统剪贴板?

    c++ - C++中文本编辑器的链接列表