Skip to main content
edited tags
Link
Martin Tournoij
  • 63.3k
  • 26
  • 199
  • 274
added 193 characters in body
Source Link
the_velour_fog
  • 3.4k
  • 3
  • 23
  • 40

which looks like it will use the filetype and run the appropriate syntax file.
To

terminal

I'm running vim inside tmux and its not detecting my terminal properly:

:set t_Co?
  t_Co=8

so I set it to 256 color like it should be

:set t_Co=256

To me this looks like Ive covered everything, but I obviously havent, why isn't syntax highlighting happening here?

which looks like it will use the filetype and run the appropriate syntax file.
To me this looks like Ive covered everything, but I obviously havent, why isn't syntax highlighting happening here?

which looks like it will use the filetype and run the appropriate syntax file.

terminal

I'm running vim inside tmux and its not detecting my terminal properly:

:set t_Co?
  t_Co=8

so I set it to 256 color like it should be

:set t_Co=256

To me this looks like Ive covered everything, but I obviously havent, why isn't syntax highlighting happening here?

Source Link
the_velour_fog
  • 3.4k
  • 3
  • 23
  • 40

Why isn't vim applying syntax highlighting to this code?

If I open a random file (in this case, say .zshrc) in a blank vim with no rc file , but with vi compatibility forcing off

vim -N -u NORC ~/.zshrc

As expected vim will launch and display .zshrc without syntax highlighting.

attempt to enable syntax highlighting

I have a file containing a collection of highlight commands called darcula.vim in

~/.vim/colors/darcula.vim

contents of ~/.vim/colors/darcula.vim

"
" Darcula colorscheme for VIM.
"

set background=dark
highlight clear

if exists("syntax_on")
  syntax reset
endif

let g:colors_name = "darcula"

hi Cursor ctermfg=188 ctermbg=250 cterm=NONE guifg=#2b2b2b guibg=#a9b7c6 gui=NONE
hi Visual ctermfg=NONE ctermbg=24 cterm=NONE guifg=NONE guibg=#214283 gui=NONE
hi CursorLine ctermfg=NONE ctermbg=236 cterm=NONE guifg=NONE guibg=#323232 gui=NONE
hi CursorColumn ctermfg=NONE ctermbg=236 cterm=NONE guifg=NONE guibg=#313335 gui=NONE
 
[ ... plus many more highlight commands ...]

at vims command line I enter

:colorscheme darcula

then, to check if the highlight commands have been loaded, I run

:hi

and yes vim is showing all the hi commands from the above darcula.vim file have been loaded.
Then I run

:syntax enable

and nothing happens

from reading :h syntax-loading I thought the syntax enable command sets up filetype autocmd recognition, as verified with:

:filetype
filetype detection:ON  plugin:OFF  indent:OFF 

and also sets up autocommand which will run the vim function SynSet() on the autocommand event Syntax, from the file $VIMRUNTIME/syntax/synload.vim

[...]
au Syntax *     call s:SynSet()

fun! s:SynSet()
  " clear syntax for :set syntax=OFF  and any syntax name that doesn't exist
  syn clear
  if exists("b:current_syntax")
    unlet b:current_syntax
  endif

  let s = expand("<amatch>")
  if s == "ON"
    " :set syntax=ON
    if &filetype == ""
      echohl ErrorMsg
      echo "filetype unknown"
      echohl None
    endif
    let s = &filetype
  elseif s == "OFF"
    let s = ""
  endif

  if s != ""
    " Load the syntax file(s).  When there are several, separated by dots,
    " load each in sequence.
    for name in split(s, '\.')
      exe "runtime! syntax/" . name . ".vim syntax/" . name . "/*.vim"
    endfor
  endif
endfun

[...]

which looks like it will use the filetype and run the appropriate syntax file.
To me this looks like Ive covered everything, but I obviously havent, why isn't syntax highlighting happening here?