I have defined a file time
jak.vim to offer custom highlighting when I take notes, however it is being applied to some files that do not have the
.jak extension. Specifically a file named
progress.jlog. Just to test if the problem was specific to that extension I renamed
progress (no extension) but experienced the same problem.
What I did:
- I created
jak.vimin the directory
- I added this line: "au BufRead, BufNewFile *.jak set filetype=jak" to the top as described in the vim reference
- I restarted vim (:x, and then reopened)
This is what my
~/.vim/ftdetect/jak.vim looks like:
~/.vim/ftdetect]% 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
And just incase you need to know this is what my
.vimrc looks like:
~/.vim/ftdetect]% 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: 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
Note: I completed all the quotes (comments) to make it easier to read
I found nsharish's post to be very helpfull. They suggested that I add this to my vimrc:
au BufRead,BufNewFile *.jak set filetype=jak
and add my
jak.vim file to
Unfortunately that code conflicts with these two lines (in my vimrc)
au BufWinLeave *.c mkview au BufWinEnter *.c silent loadview
I use these two to save my folds, cursor location, etc when loading vim (see
:help lo). If I comment out those two lines nsharish's suggestion works like a charm. With those two lines there is no highlighting in any of my files.
I marked nsharish's answer as the best answer (because it as most helpful to me). However this is how I solved the problem:
Nsharish was right I needed this line in my
syntax enable au BufRead,BufNewFile *.jak set filetype=jak
And I needed to move my
jak.vim file to
However as noted above there was a conflict with these lines:
au BufWinLeave * mkview au BufWinEnter * silent loadview
When these lines were commented the highlighting worked.
What I needed to do was to change the
...set filetype... to this:
au BufWinEnter,BufRead,BufNewFile *.jak set filetype=jak
I think that the BufWinEnter is called after the BufRead/BufNew file so the highlighting was being overwritten by the formatting saved from last time.
Thank again to nsharish for helping me to come up with this solution.