Reputation: 3983
So, I'm pretty happy that I've discovered how to set highlighting when I open a particular file in vim. I'm doing this for JavaScript files, so most of them are 'hi jsStringD' and 'hi jsFunction' etc. I use this to trigger it:
if has("autocmd")
augroup JavaScript
au!
au BufReadPost *.js call SetUpJavaScript()
augroup END
...
I also want to change the color of 'Normal' or foreground text, but only for JavaScript files.
This works to set the color:
execute 'hi Normal ctermfg=' normalText
But how do I limit it only to a certain filetype? This results in all files having 'Normal' highlighted to that color.
EDIT: Just to clarify, I open a JavaScript file and it works. I open another file (say a .jade file) and 'Normal' color remains the 'normalText' value.
Upvotes: 0
Views: 207
Reputation: 31419
Use an autocmd that only fires for the javascript file type
autocmd FileType javascript execute 'hi Normal ctermfg=' normalText
However I think this will have problems if you switch between multiple files in one session since highlighting is global.
To work around this you could add another FileType autocmd that fires on BufEnter (or something like that) that sets a default Normal highlighting.
Something like this would work (Although it will change the highlighting in splits when you change focus)
autocmd BufEnter * if (&filetype ==# 'javascript') | execute 'hi Search ctermfg=' . normalText | else | execute 'hi Search ctermfg=' . defualtText | endif
Upvotes: 2