【问题标题】:vim colorscheme not loading in the new tabvim 颜色方案未在新选项卡中加载
【发布时间】:2014-04-09 18:25:16
【问题描述】:

我一直在努力改变我的 vim 的配色方案,我终于觉得我做得对了。我正在处理 systemverilog (.sv) 文件,通常需要一次打开 4-5 个选项卡。

我在 vim 中从终端打开的第一个文件可以很好地加载颜色方案。如果我从此文件打开一个新的 vim 选项卡 (:tabnew file_name),打开另一个 sv 文件,它只会显示一种颜色。我必须打开一个新的终端选项卡才能让颜色方案在另一个文件中工作。

我的 .vimrc 文件在主目录中,还有我的 .vim 文件夹,其中包含颜色文件夹。我尝试了以下命令:

:scriptnames

在两个选项卡中,它们显示位于自定义颜色文件夹中的配色方案以及默认位置。

  1: /etc/vimrc
  2: /usr/share/vim/vim72/syntax/syntax.vim
  3: /usr/share/vim/vim72/syntax/synload.vim
  4: /usr/share/vim/vim72/syntax/syncolor.vim
  5: /usr/share/vim/vim72/filetype.vim
  6: /usr/share/vim/vim72/ftplugin.vim
  7: /home/username/.vimrc
  8: /usr/share/vim/vim72/syntax/nosyntax.vim
  9: /home/username/.vim/plugin/matchit.vim
 10: /home/username/.vim/syntax/verilog_systemverilog.vim
 11: /usr/share/vim/vim72/syntax/verilog.vim
 12: /usr/share/vim/vim72/indent.vim
 13: /home/username/.vim/colors/koehler.vim
 14: /home/username/.vim/plugin/matchit2.vim
 15: /usr/share/vim/vim72/plugin/filetype.vim
 16: /usr/share/vim/vim72/plugin/getscriptPlugin.vim
 17: /usr/share/vim/vim72/plugin/gzip.vim
 18: /usr/share/vim/vim72/plugin/matchparen.vim
 19: /usr/share/vim/vim72/plugin/netrwPlugin.vim
 20: /usr/share/vim/vim72/plugin/rrhelper.vim
 21: /usr/share/vim/vim72/plugin/spellfile.vim
 22: /usr/share/vim/vim72/plugin/tarPlugin.vim
 23: /usr/share/vim/vim72/plugin/tohtml.vim
 24: /usr/share/vim/vim72/plugin/vimballPlugin.vim
 25: /usr/share/vim/vim72/plugin/zipPlugin.vim
 26: /usr/share/vim/vim72/scripts.vim

有没有解决这个问题的方法?

编辑:我已经能够通过将以下内容添加到我的 .vimrc 文件来解决 .sv 文件的这个问题:

Au BufRead,BufNewFile *.sv set filetype=verilog

但这显然不是所有文件类型的通用解决方案。

编辑:添加 vimrc 文件的链接:vimrc file

【问题讨论】:

  • 该列表中唯一的配色方案是koehler.vim,是您修改的那个吗?您可以发布它并显示您的修改吗?你的.vimrc?另外,我认为nosyntax.vim 不应该在这里。
  • 我已经在上面添加了指向 .vimrc 文件的链接。此外,除了将“白色”更改为“浅蓝色”外,koehler.vim 没有显着变化。你会建议我用 nosyntax.vim 做什么?我当然没有首先添加它。
  • .vimrc 链接已关闭(firedrive.com 已关闭并被 Google 标记为“欺骗性”)

标签: vim color-scheme system-verilog


【解决方案1】:

你的.vimrc 是一团糟。

  • 以下几行完全没用:

    source ~/.vim/plugin/matchit.vim
    source /usr/share/vim/vim72/syntax/syntax.vim
    source ~/.vim/syntax/verilog_systemverilog.vim
    

    它们没用,因为所有这些文件都是自动获取的:在您的.vimrc 在启动期间为第一个文件获取源之后;在Syntax 事件之后(由syntax on 触发,它已经在您的.vimrc 的其他位置)第二次;在第三个文件被识别为verilog 之后。

  • 这些也一样:

    " Set up the connection between FileType and Syntax autocommands.
    " This makes the syntax automatically set when the file type is detected.
    augroup syntax
    au! FileType *      exe "set syntax=" . expand("<amatch>")
    augroup END
    

    因为 Vim 已经将其作为 filetype 机制的一部分,您可以在 .vimrc 中“打开”三次。

  • 还有这个:

    " Execute the syntax autocommands for the each buffer.
    doautoall filetype BufRead
    

    因为您的.vimrc 是在加载任何缓冲区之前获取的。该命令将在您编辑的第一个文件上执行,并且不会在当前会话中再次执行。

  • 还有这个:

    highlight Visual term=reverse  cterm=reverse  gui=reverse  guifg=Grey50
    

    因为在只在 GVim 中执行的代码块中设置终端高亮属性是没有意义的。

  • 让我们不要谈论混合制表符和空格、尾随空格和无意义的 cmets:

    " For sure anyting under .vim/ gets executed automaticall. I've checked.
    

:help new-filetype 告诉您如何添加对自定义文件类型的支持。你应该仔细阅读它(我建议方法C)。

【讨论】:

  • 当我读到你(长而正确的)答案的第一句话时,我知道是你 :-) 没有其他人会写出如此有用的咆哮!
  • @IngoKarkat,谢谢,我想这是我的商标。你的咆哮不那么“咆哮”,但也很有帮助!
  • @romainl 感谢您的意见。我会收拾烂摊子。不过,我仍然不确定,颜色方案无法加载到使用 :tabnew 从一个文件中打开的文件的原因是什么。从终端打开的第一个文件可以很好地加载颜色方案。
【解决方案2】:

您是否查看过 Amal Khailtash 在他的 SystemVerilog/OVM 语法文件中所做的事情:

vim-syntax-highlighting-systemverilog-and-ovm

过去几年我一直在使用他的文件,并且在多个选项卡和拆分窗口中突出显示 systemverilog 文件没有任何问题。

【讨论】:

    【解决方案3】:

    感谢以下命令@Ady au BufRead,BufNewFile *.sv set filetype=verilog

    我用过 au BufRead,BufNewFile * 设置文件类型=verilog 将 tabnew 中的所有文件设置为 verilog 格式。至少这样文件有一些颜色,我可以继续为不同的扩展添加不同的文件类型设置,因为我继续前进

    【讨论】:

    • 请不要添加“谢谢”作为答案。一旦您拥有足够的声誉,您就可以对您认为有帮助的问题和答案进行投票。
    猜你喜欢
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 2011-02-07
    • 1970-01-01
    • 2011-05-18
    相关资源
    最近更新 更多