six*_*ude 18 unix vim syntax-highlighting
我已经定义了一个文件时间jak.vim来在我做笔记时提供自定义突出显示,但是它被应用于一些没有.jak扩展名的文件。特别是一个名为progress.jlog. 只是为了测试问题是否特定于该扩展名,我重命名progress.jlog为progress(无扩展名)但遇到了同样的问题。
我做了什么:
jak.vim在目录中创建~/.vim/ftdetectau BufRead, BufNewFile *.jak set filetype=jak这是我的~/.vim/ftdetect/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
Run Code Online (Sandbox Code Playgroud)
以防万一你需要知道这就是我的.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: https://superuser.com/questions/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
Run Code Online (Sandbox Code Playgroud)
我发现nsharish 的帖子非常有帮助。他们建议我将它添加到我的 vimrc 中:
au BufRead,BufNewFile *.jak set filetype=jak
Run Code Online (Sandbox Code Playgroud)
并将我的jak.vim文件添加到~/.vim/syntax
不幸的是,代码与这两行冲突(在我的 vimrc 中)
au BufWinLeave *.c mkview
au BufWinEnter *.c silent loadview
Run Code Online (Sandbox Code Playgroud)
在加载 vim 时,我使用这两个来保存折叠、光标位置等(请参阅 参考资料:help lo)。如果我注释掉这两行 nsharish 的建议就像一个魅力。这两行在我的任何文件中都没有突出显示。
我将nsharish 的答案标记为最佳答案(因为它对我最有帮助)。然而,这就是我解决问题的方式:
Nsharish 是对的,我在我的.vimrc:
syntax enable
au BufRead,BufNewFile *.jak set filetype=jak
Run Code Online (Sandbox Code Playgroud)
我需要将我的jak.vim文件移动到~/.vim/syntax.
但是,如上所述,与这些行存在冲突:
au BufWinLeave * mkview
au BufWinEnter * silent loadview
Run Code Online (Sandbox Code Playgroud)
当这些行被评论时,突出显示工作。
我需要做的是将其更改...set filetype...为:
au BufWinEnter,BufRead,BufNewFile *.jak set filetype=jak
Run Code Online (Sandbox Code Playgroud)
我认为 BufWinEnter 是在BufRead/BufNew 文件之后调用的,因此突出显示被上次保存的格式覆盖。
再次感谢 nsharish 帮助我提出了这个解决方案。
asd*_*dfg 10
你试过这个吗..
语法 enable我用你的 jak.vim 文件试过这个......它对我来说很好......
au BufRead,BufNewFile *.jak set filetype=jak
打开文件,然后执行“ :set ft=jak ”,保存文件并退出vim....现在重新打开文件...语法高亮现在应该可以工作了...
mkview和loadview似乎保存了最后的语法高亮设置还....
| 归档时间: |
|
| 查看次数: |
17070 次 |
| 最近记录: |