Vim 中的配色方案在初始启动时不起作用

Colorscheme in Vim not working on initial boot up

让我先声明一下,我是 Vim 和 MacVim 的新手。我正在努力让我喜欢的配色方案发挥作用,而且我已经取得了部分成功。就目前而言,如果在我编辑到文件后键入以下内容,颜色方案将起作用:

:syntax enable

但是,在初始加载时,它不起作用。我想通过在我的 .vimrc 文件中放置语法启用,这会在加载时激活它,但这显然不起作用。到目前为止,我的 .vimrc 文件看起来像:

set nocompatible                                "We want the latest Vim settings/options

so ~/.vim/plugins.vim

filetype plugin indent on
syntax on
set backspace=indent,eol,start                  "Make backspace behave like every other editor.
let mapleader = ','                             "The default leader is \, but a comma is much better.
set number                                      "Activates line numbering.

"-----------Visuals------------"
colorscheme atom-dark                       "Sets colorscheme.
set t_CO=256                                "Use 256 colors.  This is useful for terminal Vim.
set guifont=Fira_Code:h13                   "Sets font and font height.
set linespace=15                            "Macvim-specific line height.

set guioptions-=l                       "Removes left hand scroll bar.
set guioptions-=L                       "Removes left hand scroll bar on vertically split screens.
set guioptions-=r                       "Removes right hand scroll bar.
set guioptions-=R                       "Removes right hand scroll bar on vertically split screens.

还有更多内容,但我认为这不相关。另外,如果重要的话,我将配色方案保存在我的 ~/.vim/colors 文件夹中。最后,我大部分时间都在使用 MacVim。

要让配色方案在初始加载时运行,我缺少什么?或者只是要求我每次都手动启用语法?

提前感谢您的帮助!

编辑

我的 .gvimrc 文件:

 set nocompatible              " be iMproved, required
 filetype off                  " required
 set modelines=0              " sets modeline to 0 for security



 " Turn on line numbers
 set number

首先,您打错了t_CO;这是 t_Co.

其次,那条线完全没用。删除它并正确配置您的终端仿真器。

第三,colorscheme atom-dark 仅适用于 MacVim GUI。如果您希望 atom-dark 在 Vim 中工作,您需要使用 atom-dark-256 变体。请注意,atom-dark-256 是机器生成的,因此 VimMacVim 之间可能会有 许多 差异。

四、使用the project's issue tracker.

您应该从 .gvimrc 中删除 filetype off。首先,请参阅 :help gvimrc:

The gvimrc file is where GUI-specific startup commands should be placed. It is always sourced after the vimrc file. If you have one then the $MYGVIMRC environment variable has its name.

您的 .vimrc 文件集 filetype plugin indent on。但是 .gvimrc 将在 之后 .vimrc 文件中获取,并再次设置 filetype off。因此,您的 MacVim.

不会执行任何文件类型检测

另外,我建议您 .gvimrc 只包含特定于 GUI 的配置。这意味着您可以删除

set compatible
filetype off
set number

来自您的 .gvimrc。你也可以把set modelines=0移到.vimrc,不过我觉得没必要,你也可以去掉。

此外,您的 .vimrc 中还有一些选项仅适用于启用 GUI Vim,例如 guifontlinespaceguioptions。要使您的 .vimrc 也能在终端 Vim 上工作,请用 if has('gui_running') 包装该选项。所以 .vimrc 将是:

set nocompatible                                "We want the latest Vim settings/options

so ~/.vim/plugins.vim

filetype plugin indent on
syntax on
set backspace=indent,eol,start                  "Make backspace behave like every other editor.
let mapleader = ','                             "The default leader is \, but a comma is much better.
set number                                      "Activates line numbering.

"-----------Visuals------------"
colorscheme atom-dark                       "Sets colorscheme.
set t_Co=256                                "Use 256 colors.  This is useful for terminal Vim.

if has('gui_running')
  set guifont=Fira_Code:h13               "Sets font and font height.
  set linespace=15                        "Macvim-specific line height.

  set guioptions-=l                       "Removes left hand scroll bar.
  set guioptions-=L                       "Removes left hand scroll bar on vertically split screens.
  set guioptions-=r                       "Removes right hand scroll bar.
  set guioptions-=R                       "Removes right hand scroll bar on vertically split screens.
endif