0

目前我使用一个相对简单的代码片段来动态更改vim中的缓冲区颜色方案代码 -在SO上详细介绍

这个提议的解决方案看起来更全面 - 我只是不确定如何实现它。

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 计划?
还是我最好坚持使用简单的两行代码来切换配色方案?

4

1 回答 1

2

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

:autocmd FileType sql ColorScheme SummerFruit256

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

您可以像往常一样通过:ColorDefault或在代码段之前设置默认方案。

于 2013-05-24T07:33:40.940 回答