我已经定义了一个文件时间,jak.vim
以便在记笔记时提供自定义突出显示,但是它已应用于一些没有.jak
扩展名的文件。特别是名为的文件progress.jlog
。只是为了测试问题是否特定于该扩展名,我重命名progress.jlog
为progress
(无扩展名)但遇到了相同的问题。
我做了什么:
- 我
jak.vim
在目录中创建~/.vim/ftdetect
- 我在vim参考中描述了此行:“ au BufRead,BufNewFile * .jak set filetype = jak”到顶部
- 我重新启动了vim(:x,然后重新打开)
这是我的~/.vim/ftdetect/jak.vim
样子:
~/.vim/ftdetect][505]% cat jak.vim
au BufRead, BufNewFile *.jak set filetype=jak
syn region JakeSubtitle start=+==+ end=+==+
highlight JakeSubtitle ctermbg=black ctermfg=DarkMagenta
syn region JakeTitle start=+===+ end=+===+
highlight JakeTitle ctermbg=black ctermfg=yellow
syn region JakeMasterTitle start=+====+ end=+====+
highlight JakeMasterTitle cterm=bold term=bold ctermbg=black ctermfg=LightBlue
syn region emphasis start=+<em>+ end=+</em>+
highlight emphasis ctermbg=black ctermfg=yellow
" makes all of the numbered items bold."
" (this works I just don't like the effect. Decided to change to just highlight the "number)
"syn region numberedItem start=+^\t*\d*)+ end=+\n+"
syn match numberedItem +^\t*\d*)+
highlight numberedItem cterm=bold
以防万一您需要知道这是我的.vimrc
模样:
~/.vim/ftdetect][508]% cat ../../.vimrc
"on will override defaults set. Enable will allow you to set defaults."
" also turns on filetype"
"syntax on"
syntax enable
set nocompatible
" ???"
set backspace=2
"Auto indent"
set ai
"Map jj to Esc so that you do not have to reach for the Esc button"
imap jj <Esc>
"do not allow the search to wrap around the screen, must stop at the bottom."
set nowrapscan
"when doing a search highlight all occurances"
":set hlsearch"
"stop text from wrapping on the screen"
set nowrap
"turn the mouse on while in insert mode"
set mouse=i
"attempting to highlight specific keywords so it is easy to see in code."
"see help e410 for more info."
"see this post I created: /superuser/110054/custom-vim-highlighting"
"Legal colors: Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta,"
"Brown, DarkYellow, LightGray, LightGrey, Gray, Grey, DarkGray, DarkGrey,"
"Blue, LightBlue, Green, LightGreen, Cyan, LightCyan, Red, LightRed, Magenta,"
"LightMagenta, Yellow, LightYellow, White"
syn keyword JakeKeywords Question TODO Answer JAKEHTTPS PossibleProblem
highlight JakeKeywords cterm=bold term=bold ctermbg=black ctermfg=Blue
"for case-insensitve searches"
set ignorecase
"Override the 'ignorecase' option if the search pattern contains upper"
"case characters. Only used when the search pattern is typed and"
"'ignorecase' option is on."
set smartcase
"use indents as the folding method"
set foldmethod=indent
"make vim save and load the folding of the document each time it loads"
"also places the cursor in the last place that it was left."
au BufWinLeave * mkview
au BufWinEnter * silent loadview
注意:我已完成所有引号(注释)以使其更易于阅读
更新资料
我发现nsharish的帖子非常有帮助。他们建议我将此添加到我的vimrc中:
au BufRead,BufNewFile *.jak set filetype=jak
并将我的jak.vim
文件添加到~/.vim/syntax
不幸的是,代码与这两行冲突(在我的vimrc中)
au BufWinLeave *.c mkview
au BufWinEnter *.c silent loadview
加载vim时,我用这两个保存折叠,光标位置等(请参阅参考资料:help lo
)。如果我将这两行注释掉,那么nsharish的建议就像一个魅力。在这两行中,我的任何文件中都没有突出显示。
结论
我将nsharish的答案标记为最佳答案(因为它对我最有帮助)。但是,这就是我解决问题的方法:
Nsharish是对的,我需要在我的这行内容.vimrc
:
syntax enable
au BufRead,BufNewFile *.jak set filetype=jak
而且我需要将jak.vim
文件移到~/.vim/syntax
。
但是,如上所述,这些行存在冲突:
au BufWinLeave * mkview
au BufWinEnter * silent loadview
当评论这些行时,突出显示起作用。
我需要做的是将其更改...set filetype...
为:
au BufWinEnter,BufRead,BufNewFile *.jak set filetype=jak
我认为BufWinEnter是在 BufRead / BufNew文件之后调用的,因此突出显示被上次保存的格式所覆盖。
再次感谢nsharish帮助我提出这个解决方案。