自定义语法着色vim [英] Custom syntax coloring vim
问题描述
在vim中,您可以调用一个主题,例如"colo:desert"并为某些未着色的语法着色吗,比如说我想将"Access Validation"和"Panel"一词着色为绿色,Vim可以满足要求吗?那?
In vim can you call a theme for example, 'colo:desert' and colorize certain syntax which are not colorized like lets say i wanted to colorize the words "Access Validation" and "Panel" to green will Vim let met do that?
下面是我的沙漠主题,我用它来着色语法
Below is my desert theme which i use to colorize my syntax
" cool help screens
" :he group-name
" :he highlight-groups
" :he cterm-colors
set background=dark
if version > 580
" no guarantees for version 5.8 and below, but this makes it stop
" complaining
hi clear
if exists("syntax_on")
syntax reset
endif
endif
let g:colors_name="desert"
hi Normal guifg=White guibg=grey20
" highlight groups
hi Cursor guibg=khaki guifg=slategrey
"hi CursorIM
"hi Directory
"hi DiffAdd
"hi DiffChange
"hi DiffDelete
"hi DiffText
"hi ErrorMsg
hi VertSplit guibg=#c2bfa5 guifg=grey50 gui=none
hi Folded guibg=grey30 guifg=gold
hi FoldColumn guibg=grey30 guifg=tan
hi IncSearch guifg=slategrey guibg=khaki
"hi LineNr
hi ModeMsg guifg=goldenrod
hi MoreMsg guifg=SeaGreen
hi NonText guifg=LightBlue guibg=grey30
hi Question guifg=springgreen
hi Search guibg=peru guifg=wheat
hi SpecialKey guifg=yellowgreen
hi StatusLine guibg=#c2bfa5 guifg=black gui=none
hi StatusLineNC guibg=#c2bfa5 guifg=grey50 gui=none
hi Title guifg=indianred
hi Visual gui=none guifg=khaki guibg=olivedrab
"hi VisualNOS
hi WarningMsg guifg=salmon
"hi WildMenu
"hi Menu
"hi Scrollbar
"hi Tooltip
" syntax highlighting groups
hi Comment guifg=SkyBlue
hi Constant guifg=#ffa0a0
hi Identifier guifg=palegreen
hi Statement guifg=khaki
hi PreProc guifg=indianred
hi Type guifg=darkkhaki
hi Special guifg=navajowhite
"hi Underlined
hi Ignore guifg=grey40
"hi Error
hi Todo guifg=orangered guibg=yellow2
" color terminal definitions
hi SpecialKey ctermfg=darkgreen
hi NonText cterm=bold ctermfg=darkblue
hi Directory ctermfg=darkcyan
hi ErrorMsg cterm=bold ctermfg=7 ctermbg=1
hi IncSearch cterm=NONE ctermfg=yellow ctermbg=green
hi Search cterm=NONE ctermfg=grey ctermbg=blue
hi MoreMsg ctermfg=darkgreen
hi ModeMsg cterm=NONE ctermfg=brown
hi LineNr ctermfg=3
hi Question ctermfg=green
hi StatusLine cterm=bold,reverse
hi StatusLineNC cterm=reverse
hi VertSplit cterm=reverse
hi Title ctermfg=5
hi Visual cterm=reverse
hi VisualNOS cterm=bold,underline
hi WarningMsg ctermfg=1
hi WildMenu ctermfg=0 ctermbg=3
hi Folded ctermfg=darkgrey ctermbg=NONE
hi FoldColumn ctermfg=darkgrey ctermbg=NONE
hi DiffAdd ctermbg=4
hi DiffChange ctermbg=5
hi DiffDelete cterm=bold ctermfg=4 ctermbg=6
hi DiffText cterm=bold ctermbg=1
hi Comment ctermfg=darkcyan
hi Constant ctermfg=brown
hi Special ctermfg=5
hi Identifier ctermfg=6
hi Statement ctermfg=3
hi PreProc ctermfg=5
hi Type ctermfg=2
hi Underlined cterm=underline ctermfg=5
hi Ignore cterm=bold ctermfg=7
hi Ignore ctermfg=darkgrey
hi Error cterm=bold ctermfg=7 ctermbg=1
:setf sql
:set number
:highlight LineNr Ctermfg=red
:set nowrap
"vim: sw=4
推荐答案
您可以添加任意语法突出显示.在我的 .vimrc
中,我用红色标记了结尾的空白:
You can add arbitrary syntax highlighting. In my .vimrc
, I have one to mark trailing whitespace in red:
highlight ExtraWhitespace ctermbg=1 guibg=red
match ExtraWhitespace /\s\+$/
您可以这样做:
highlight StackOverflow ctermfg=DarkGreen
match StackOverflow /Panel\|Access Validation/
然后,您只需设置为 BufWinEnter
, BufWinLeave
, InsertEnter
运行 match
命令的autocmds,以及 InsertLeave
:
Then you just have to set up autocmds that runs the match
command for BufWinEnter
, BufWinLeave
, InsertEnter
, and InsertLeave
:
autocmd BufWinEnter * match StackOverflow /Panel\|Access Validation/
autocmd BufWinLeave * match StackOverflow /Panel\|Access Validation/
autocmd InsertEnter * match StackOverflow /Panel\|Access Validation/
autocmd InsertLeave * match StackOverflow /Panel\|Access Validation/
如果只希望将其应用于特定类型的文件,当然可以做得更细.
You can of course do it more fine-grained, if you just want it to apply to specific kinds of files.
这篇关于自定义语法着色vim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!