【问题标题】:how can I change the colorscheme programmatically with vimscript?如何使用 vimscript 以编程方式更改颜色方案?
【发布时间】:2021-11-20 13:28:35
【问题描述】:

我想更改 vimscript 中的颜色方案,例如:

let g:scheme = "default"
colorscheme scheme

我收到以下错误:

colorscheme "scheme" cannot be found

为什么当我执行 :colorscheme 命令时变量 'scheme' 没有链接到字符串 'default' ?

【问题讨论】:

    标签: variables vim neovim color-scheme


    【解决方案1】:

    “vimscript”或“viml 脚本”或其他任何东西(很难命名)实际上只是一系列 Ex 命令,有时称为“冒号命令”。

    这些命令中的大多数,比如:colorscheme,只接受直接的字符串作为输入,甚至不尝试评估变量/表达式:

    colorscheme scheme
    

    在您的示例中,scheme 被视为字符串,而不是变量,因此您当然会收到错误,因为您没有名为 scheme 的颜色方案。

    在那些相对常见的情况下,变量必须在传递给 Ex 命令之前进行评估。这是通过:help :execute:help expr-.. 运算符完成的:

    execute 'colorscheme ' .. scheme
    

    【讨论】:

      猜你喜欢
      • 2016-07-03
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多