4

So, for whatever reason, whenever I open an HTML or CSS file, Vim syntax highlighting doesn't seem to work. In an html file, all that shows are read brackets. In a css file, there are very few colors. However, if I run the command syntax on explicitly, the syntax highlighting begins to work. I've checked my ~/.vimrc and syntax on is in there. All other file types work just fine. I have absolutely no idea as to what's causing the problem. Here are some screenshots:

Before:

Here's before I enter <code>syntax on</code>

After:

and after I enter <code>syntax on</code>

Also, here is my vimrc:

" ----------------------------------------------------------------------
"  Vim package manager
" ----------------------------------------------------------------------

call plug#begin('~/.vim/bundle')

" ----------------------------------------------------------------------
"  My Plugins
" ----------------------------------------------------------------------

" Unite.vim
Plug 'Shougo/vimproc.vim', {'do': 'make'}
Plug 'Shougo/neomru.vim'
Plug 'Shougo/unite.vim'

" Improves editing efficiency.
Plug 'SirVer/ultisnips'
Plug 'scrooloose/syntastic'
Plug 'Valloric/YouCompleteMe', {'do': './install.sh --clang-completer'}
Plug 'tpope/vim-surround'
Plug 'godlygeek/tabular'
Plug 'jiangmiao/auto-pairs'
Plug 'tomtom/tcomment_vim'
Plug 'mileszs/ack.vim'
Plug 'henrik/vim-qargs'
Plug 'nelstrom/vim-visual-star-search'
Plug 'marijnh/tern_for_vim', {'do': 'npm install'}
Plug 'mattn/emmet-vim'

" Does stuff for me
Plug 'mklabs/vim-fetch'

" Makes things look better.
Plug 'altercation/vim-colors-solarized'
Plug 'bling/vim-airline'
Plug 'oblitum/rainbow'
Plug 'octol/vim-cpp-enhanced-highlight'

" Improves Vim functionality.
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'sjl/gundo.vim'
Plug 'mhinz/vim-startify'
Plug 'zhaocai/GoldenView.Vim'
Plug 'majutsushi/tagbar'
Plug 'wavded/vim-stylus'
Plug 'digitaltoad/vim-jade'

" God damn you tpope, I don't know here to put this shit.
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-repeat'

" ----------------------------------------------------------------------
"  Important
" ----------------------------------------------------------------------

call plug#end()

set nocompatible
filetype plugin indent on

set pastetoggle=<F3>

" ----------------------------------------------------------------------
"  Plugin Settings
" ----------------------------------------------------------------------

" Unite.vim
call unite#filters#matcher_default#use(['matcher_fuzzy'])
call unite#filters#sorter_default#use(['sorter_rank'])

let g:unite_source_history_yank_enable=1
let g:unite_enable_start_insert=1

" YouCompleteMe
let g:ycm_global_ycm_extra_conf="~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"
let g:ycm_confirm_extra_conf=0
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_min_num_of_chars_for_completion=1

" Ultisnips
let g:UltiSnipsEditSplit="vertical"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<S-tab>"
let g:UltiSnipsListSnippets="<c-e>"

" syntastic
let g:syntastic_cpp_compiler='gcc'
let g:syntastic_cpp_compiler_options=' -std=c++11 -stdlib=libc++'

" vim-airline
let g:airline_powerline_fonts=1
let g:airline_theme='solarized'

" rainbow
let g:rainbow_active=1

" auto-pairs
let g:AutoPairsFlyMode=1

" GoldenView.vim
let g:goldenview__enable_default_mapping=0

" Ack.vim
let g:ack_autofold_results=1
let g:ackpreview=1

" Emmet-vim
let g:user_emmet_leader_key='<C-E>'

" ----------------------------------------------------------------------
"  Moving around, searching and patterns
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Tags
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Displaying text
" ----------------------------------------------------------------------
"
set relativenumber " Display line numbers relative to cursor position.

set list " Don't show invisible characters.
set listchars=tab:▸\ ,eol:¬ " Set invisible character repsentations.

" ----------------------------------------------------------------------
"  Syntax, highlighting and spelling
" ----------------------------------------------------------------------

set incsearch " Show match for partly typed search command.
set ignorecase " Ignore case when using a search pattern.
set smartcase " Override 'ignorecase' when pattern has upper case
                            " characters.

set cursorline " Highlight the screen line of the cursor.
set colorcolumn=72 " Columan to highlight.

syntax on " Turns on syntax highlighting
syntax sync fromstart " The file will be parsed from the start

" For solarized colorscheme
let g:solarized_termcolors=256 " Use 8 bit colors.
let g:solarized_visibility="low" " Visibility of invisible characters.

set background=light " Set colorscheme shade variant
colorscheme solarized " Set default colorscheme

" ----------------------------------------------------------------------
"  Multiple windows
" ----------------------------------------------------------------------

set hidden " Unload a buffer when no longer shown in a window.

set laststatus=2 " Display vim-airline always.

" ----------------------------------------------------------------------
"  Multiple tab pages
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Terminal
" ----------------------------------------------------------------------

set ttyfast " Terminal connection is fast.

" ----------------------------------------------------------------------
"  Using the mouse
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  GUI
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Printing
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Messages and info
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Selecting text
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Editing text
" ----------------------------------------------------------------------

set formatoptions=cqn
set textwidth=72

set completeopt=menuone,longest,preview

" ----------------------------------------------------------------------
"  Tabs and indenting
" ----------------------------------------------------------------------

set tabstop=2 " Number of spaces a <Tab> in the text stands for.
set shiftwidth=2 " Number of spaces used for each step of (auto)indent.
set softtabstop=2 " If non-zero, number of spaces to insert for a <Tab>.
set smarttab " A <Tab> in an indent inserts 'shiftwidth' spaces.
set noexpandtab " Do not expand <Tab> to spaces in Insert mode.

set autoindent " Automatically set the indent of a new line.
set copyindent " Copy whitespace for indenting from previous line.

" ----------------------------------------------------------------------
"  Folding
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Diff mode
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Mapping
" ----------------------------------------------------------------------

let mapleader=','

" No more escape key! Yay!
inoremap jk <Esc>

" Edit $MYVIMRC in new tab.
nnoremap <leader>v :tabedit ~/.dotfiles/files/vimrc<CR>

" Save current buffer.
nnoremap <leader>w :w<CR>

" Delete current buffer.
nnoremap <leader>d :bd %<CR>

" Strips trailing whitespace.
nnoremap <leader>W :call Preserve("%s/\\s\\+$//e")<CR>
" Formats entire buffer.
nnoremap _= :call Preserve("normal gg=G")<CR>

" Better window navigation.
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l

" Directory navigation.
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<CR>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%

" If you forgot to sudo Vim
cnoremap w!! w !sudo tee % >/dev/null

" Unite.vim
nnoremap <C-p>       :<C-u>Unite -buffer-name=files  -start-insert file_rec/async:!<CR>
nnoremap <leader>f :<C-u>Unite -buffer-name=files    -start-insert file<CR>
nnoremap <leader>r :<C-u>Unite -buffer-name=mru      -start-insert file_mru<CR>
nnoremap <leader>y :<C-u>Unite -buffer-name=yank     history/yank<CR>
nnoremap <leader>b :<C-u>Unite -buffer-name=buffer buffer<CR>

" YouCompleteMe
nnoremap<leader>jd :YcmCompleter GoTo<CR>

" vim-fugitive
nnoremap <leader>gb  :Gblame<CR>
nnoremap <leader>gc  :Gcommit -S<CR>
nnoremap <leader>gca :Gcommit -aS<CR>
nnoremap <leader>gd  :Gdiff<CR>
nnoremap <leader>gl  :Gpull<CR>
nnoremap <leader>gp  :Gpush<CR>
nnoremap <leader>gr  :Gread<CR>
nnoremap <leader>gs  :Gstatus<CR>
nnoremap <leader>gw  :Gwrite<CR>

" gundo.vim
nnoremap <leader>gu :GundoToggle<CR>

" GoldenView.vim
nmap <silent> <leader>s <Plug>GoldenViewSplit :e .<CR>
nmap <silent> <F8>          <Plug>GoldenViewSwitchMain
nmap <silent> <S-F8>        <Plug>GoldenViewSwitchToggle

" Tagbar

nnoremap <leader>t :TagbarToggle<CR>

" ----------------------------------------------------------------------
"  Reading and writing files
" ----------------------------------------------------------------------

set backup " Keep a backup after overwriting a file.
set writebackup " Write a backup file before overwriting a file.
set backupdir=~/.vim/.backup// " List of directories to put backup files
" in.

" ----------------------------------------------------------------------
"  The swap file
" ----------------------------------------------------------------------

set directory=~/.vim/.swp_files// " Directory to keep .swp files in.

" ----------------------------------------------------------------------
"  Command line editing
" ----------------------------------------------------------------------

set wildmenu " Command-line completion shows a list of matches.
set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " Ignore version management.

" ----------------------------------------------------------------------
"  Executing external commands
" ----------------------------------------------------------------------

set formatprg=par\ -req" Use par for paragraph formatting.

" ----------------------------------------------------------------------
"  Running make and jumping to errors
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Language specific
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Multi-byte characters
" ----------------------------------------------------------------------

" ----------------------------------------------------------------------
"  Various
" ----------------------------------------------------------------------

command! -nargs=* Stab call Stab() " Sets tabstop, shiftwidth, and
" softtabstop to same value.
command! -nargs=* -complete=file AckReplace call AckReplace(<f-args>) " Sets tabstop, shiftwidth, and

" ----------------------------------------------------------------------
" Autocmds
" ----------------------------------------------------------------------

if has("autocmd") " If Vim was compiled with autocmd support.
    augroup Tabs " Set tab stops based on file type.
        autocmd!
        autocmd FileType make setlocal ts=8 sts=8 sw=8 noexpandtab
    augroup end

    augroup VariousFileTypes
        autocmd!
        autocmd FileType help nmap <buffer> <C-c> :q<CR>
        autocmd FileType qf nmap <buffer> <C-c> :q<CR>
    augroup end

    augroup WritePre " All BufWritePre autocommands.
        autocmd!
        autocmd BufWritePre * :call Preserve("%s/\\s\\+$//e")
    augroup end

    augroup WritePost " All BufWritePost autocommands.
        autocmd!
        autocmd BufWritePost .vimrc,vimrc source $MYVIMRC
    augroup end

    augroup TextEditing
        autocmd!
        autocmd FileType markdown,md,txt setlocal formatoptions+=ta
        autocmd FileType tex,markdown,md,txt,gitcommit setlocal spell
    augroup end

    augroup Number
        autocmd!
        autocmd InsertEnter * :set number norelativenumber
        autocmd InsertLeave * :set relativenumber nonumber
    augroup end

    augroup Plugins
        autocmd!
        autocmd FileType unite imap <buffer> <C-j> <Plug>(unite_select_next_line)
        autocmd FileType unite imap <buffer> <C-k> <Plug>(unite_select_previous_line)
        autocmd FileType unite imap <silent><buffer><expr> <C-t> unite#do_action('tabopen')
        autocmd FileType unite imap <silent><buffer><expr> <C-x> unite#do_action('split')
        autocmd FileType unite imap <silent><buffer><expr> <C-v> unite#do_action('vsplit')
        autocmd Filetype unite nmap <buffer> <Esc> <Plug>(unite_exit)
        autocmd Filetype unite nmap <buffer> <C-c> <Plug>(unite_exit)

        autocmd BufEnter * exec "inoremap <buffer> <silent> " . g:UltiSnipsExpandTrigger . " <c-r>=g:UltiSnips_Complete()<CR>"
    augroup end
endif

" ----------------------------------------------------------------------
" Functions
" ----------------------------------------------------------------------

" Set tabstop, softtabstop and shiftwidth to the same value.
function! Stab()
    let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
    if l:tabstop > 0
        let &l:sts = l:tabstop
        let &l:ts = l:tabstop
        let &l:sw = l:tabstop
    endif
endfunction

function! Preserve(command)
    " Preparation: save last search, and cursor position.
    let _s=@/
    let l = line(".")
    let c = col(".")
    " Do the business:
    execute a:command
    " Clean up: restore previous search history, and cursor position
    let @/=_s
    call cursor(l, c)
endfunction

function! AckReplace(...)
    if (a:0 > 1)
        let search_args = a:000[:-2]
        let search_pattern = SearchPattern(search_args)
        let replacement = a:000[-1]
    else
        let search_args = ['']
        let search_pattern = @/
        let replacement = a:1
    endif

    execute 'Ack ' . search_pattern . ' .'
    execute 'Qdo %s/' . search_args[0] . '/' . replacement . '/'
endfunction

function! SearchPattern(search_args)
    let search_pattern = ""
    let j = 0
    for i in a:search_args
        if (j)
            let search_pattern = search_pattern . ' ' . i
        else
            let search_pattern = search_pattern . i
        endif
        let j+= 1
    endfor
    return search_pattern
endfunction

function! g:UltiSnips_Complete()
    call UltiSnips#ExpandSnippetOrJump()
    if g:ulti_expand_or_jump_res == 0
        if pumvisible()
            return "\<c-n>"
        else
            return "\<tab>"
        endif
    endif

    return ""
endfunction
8
  • What else is in your .vimrc? Commented Apr 13, 2015 at 4:32
  • A lot. It's 456 lines Commented Apr 13, 2015 at 4:36
  • I can post it though. It's really well organized. Commented Apr 13, 2015 at 4:37
  • If you remove all your plugins, does it work as expected? Commented Apr 13, 2015 at 4:42
  • Hmm.. It looks like it does. Do you have any ideas as to which plugin could be causing the problem? Or do you know any ways I could find out without testing each plugin? Commented Apr 13, 2015 at 4:45

2 Answers 2

11

So, it turns out that one of my plugins was causing the issue. After some trial and error, I found out that it was the rainbow plugin I had installed. It was matching the brackets and overwriting Vim's default HTML syntax. I removed that plugin (which wasn't very useful anyways) and everything works normally! Thank you everyone!

Sign up to request clarification or add additional context in comments.

4 Comments

I have a situation where I need the plugin. As it is matching the pair of keywords like - <begin/end>. Please help...
rainbow did the same problem here
Put this on your .vimrc for loading it for specific file types: au FileType python, c,cpp,objc,objcpp call rainbow#load()
I started using the luochen1990/rainbow plugin and it solved everything!
0

Edit ~/.vimrc file by typing the command: vi ~/.vimrc

Append the following option

syntax on

Save and close the file

Now reopen your file with syntax highlighted.

Source here

1 Comment

OP says that option is already in their .vimrc, and that a plugin was the cause of the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.