语法高亮适用于gvim(vim的GUI版本)但不适用于vim(基于终端的vim)

问题描述 投票:-2回答:1

我是vim的新手,我想在vim中编码。我已经在TypeScript中安装了语法高亮JSX的必要插件,一切都适用于Vim的GUI版本,但不适用于基于终端的Vim。请帮我弄明白这个问题。下面是我用于语法高亮的插件。

  1. 对于TypeScript:https://github.com/leafgarland/typescript-vim
  2. 对于TypeScript中的JSX:https://github.com/peitalin/vim-jsx-typescript

我正在使用Vundle来安装插件。我尝试用上面提到的第二个插件的README部分中给出的颜色进行一些自定义。根据当我使用hi命令时,它对基于终端的Vim没有任何影响,但它在基于GUI的Vim上工作得非常好。另外,如果可能的话,请指向我的任何文章/博客,以便初学者了解更多有关vim和vimscript的信息。

编辑:

我正在尝试在TypeScript for React Development中为JSX设置语法高亮,我已经安装了上面的插件来实现这一点。以下是我的.vimrc文件的内容。

set nocompatible                " choose no compatibility with legacy vi syntax enable
set encoding=utf-8
set showcmd                     " display incomplete commands
set t_Co=256
filetype plugin indent on       " load file type plugins + indentation

"" monkai theme
syntax enable
colorscheme monokai

set nu
set guifont=monacob\ bold\ 9

highlight ColorColumn ctermbg=gray
set colorcolumn=80

"" Whitespace
set nowrap                      " don't wrap lines
set tabstop=2 shiftwidth=2      " a tab is two spaces (or set this to 4)
set expandtab                   " use spaces, not tabs (optinal)
set backspace=indent,eol,start  " backspace through everything in insert mode

"" Searching
set hlsearch                    " highlight matches
set incsearch                   " incremental searching
set ignorecase                  " searches are case insensitive...
set smartcase                   " ... unless they contain at least one capital letter

" set the runtime path to include Vundle and initialize
set rtp +=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'tpope/vim-fugitive.git'
Plugin 'tpope/vim-rails'
Plugin 'leafgarland/typescript-vim'
Plugin 'peitalin/vim-jsx-typescript'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" autocmd FileType typescript.tsx setlocal commentstring={/*\ %s\ */}
autocmd BufNewFile,BufRead *.tsx,*.jsx set filetype=typescript.tsx
autocmd BufNewFile,BufRead *.ts,*.js set filetype=typescript.jsx

" dark red
hi tsxTagName guifg=#E06C75

" orange
hi tsxCloseString guifg=#F99575
hi tsxCloseTag guifg=#F99575
hi tsxAttributeBraces guifg=#F99575
hi tsxEqual guifg=#F99575

" yellow
hi tsxAttrib guifg=#F8BD7F cterm=italic

下面是Vim enter image description here的GUI版本中JSX语法高亮的截图

下面是终端版本Vim enter image description here中JSX语法高亮的屏幕截图

正如我们在.vimrc和截图中看到的那样,在文件末尾声明的JSX标签颜色等对Gvim工作正常,但不适用于基于终端的vim。请帮我理解我在这里做错了什么。

typescript vim vi vim-plugin vim-syntax-highlighting
1个回答
0
投票
" dark red
hi tsxTagName guifg=#E06C75

使用guifg属性,您只需为GVIM定义颜色。

从Vim 8开始,就有了:help 'termguicolors'选项;你可以尝试:set termguicolors;一些终端确实支持这一点。

如果不这样做,你必须通过:set t_Co? / ctermfg属性分别定义颜色终端的颜色(来自有限的调色板,具体取决于可用颜色的数量,ctermbg会告诉你)。例如:

hi tsxTagName guifg=#E06C75 ctermfg=DarkRed

Alternative approaches via plugins

CSApprox这样的插件可以采用GUI颜色定义并将它们转换为紧密匹配的256色cterm调色板,用于高色终端。这有助于使用颜色方案,否则只从平淡的默认16色终端调色板中选择,或仅提供GUI颜色定义。

csexact采用了另一种方法,它修改了(支持的)终端的调色板,使其与Vim的GUI颜色完全匹配。

© www.soinside.com 2019 - 2024. All rights reserved.