【问题标题】:Implementing more complex color scheme code for vim为 vim 实现更复杂的配色方案代码
【发布时间】:2013-05-24 07:07:05
【问题描述】:

目前我使用比较简单的sn-p代码来动态改变vim中的缓冲区配色方案代码-detailed here on SO

This proposed solution 看起来更全面 - 我只是不确定如何实现它。

if has('autocmd')
    " change colorscheme depending on current buffer
    " if desired, you may set a user-default colorscheme before this point,
    " otherwise we'll use the Vim default.
    " Variables used:
        " g:colors_name : current colorscheme at any moment
        " b:colors_name (if any): colorscheme to be used for the current buffer
        " s:colors_name : default colorscheme, to be used where b:colors_name hasn't been set
    if has('user_commands')
        " User commands defined:
            " ColorScheme <name>
                " set the colorscheme for the current buffer
            " ColorDefault <name>
                " change the default colorscheme
        command -nargs=1 -bar ColorScheme
            \ colorscheme <args>
            \ | let b:colors_name = g:colors_name
        command -nargs=1 -bar ColorDefault
            \ let s:colors_name = <q-args>
            \ | if !exists('b:colors_name')
                \ | colors <args>
            \ | endif
    endif
    if !exists('g:colors_name')
        let g:colors_name = 'default'
    endif
    let s:colors_name = g:colors_name
    au BufEnter *
        \ let s:new_colors = (exists('b:colors_name')?(b:colors_name):(s:colors_name))
        \ | if s:new_colors != g:colors_name
            \ | exe 'colors' s:new_colors
        \ | endif
endif

我需要取消注释上述哪些部分?
我在哪里添加我的默认方案 pyte?
它在哪里发现如果它是一个 fuletype sql 然后制定 SummerFruit256 计划?
还是我最好还是坚持使用简单的两行代码来切换配色方案?

【问题讨论】:

  • 我不确定我是否理解根据当前文件类型更改整个程序外观的意义。
  • @romainl - 你不考虑配色方案吗?
  • 我只使用一种配色方案。
  • 我非常喜欢几个配色方案的想法 - 让我对其中一个感到厌烦:只是个人选择

标签: vim


【解决方案1】:

sn-p 定义了一个自定义的:ColorScheme 命令,用于设置缓冲区本地方案。您可以通过调用文件类型的命令来配置自己的文件,例如:

:autocmd FileType sql ColorScheme SummerFruit256

或将ColorScheme SummerFruit256 命令放入~/.vim/after/ftplugin/sql.vim

您可以通过:ColorDefault 设置默认方案,或者像往常一样在sn-p 之前设置它

【讨论】:

  • 我正在尝试实现your interim code(不像我目前的两个班轮那么简单,但不像上面那么复杂),但这失败了吗? :autocmd BufEnter,FileType * \ if &amp;ft ==# 'sql' colorscheme SummerFruit256 | \ elseif &amp;ft ==? 'python' | colorscheme IntelliJ' | \ else | colorscheme pyte | \ endif
  • Error detected while processing BufEnter Auto commands for "*": E10: \ should be followed by /, ? or &amp;
  • Grr,那个搞砸了。同样: \ 是行继续字符;它们必须出现在新行的开头。如果要将所有内容放在一行上,请删除 \.
  • 好的 - 仍然收到错误消息 - 我将创建一个新问题,因为它更具体地说明了 vim 脚本中空格和 \ 字符的使用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-06
  • 2018-12-25
  • 2018-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-08
相关资源
最近更新 更多