Vim HTML语法突出显示不起作用

时间:2015-04-13 04:30:41

标签: html vim syntax vim-syntax-highlighting

因此,无论出于何种原因,每当我打开HTML或CSS文件时,Vim语法突出显示似乎都不起作用。在html文件中,所有显示的都是读括号。在css文件中,颜色非常少。但是,如果我显式运行命令syntax on,则语法突出显示开始起作用。我已经检查了我的〜/ .vimrc,syntax on就在那里。所有其他文件类型都可以正常工作。我完全不知道导致问题的是什么。以下是一些截图:

在:

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

后:

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

另外,这是我的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

2 个答案:

答案 0 :(得分:7)

所以,事实证明我的一个插件导致了这个问题。经过一些反复试验,我发现它是我安装的彩虹插件。它匹配括号并覆盖Vim的默认HTML语法。我删除了这个插件(反正不是很有用),一切正常!谢谢大家!

答案 1 :(得分:0)

通过键入以下命令来编辑~/.vimrc文件:vi ~/.vimrc

附加以下选项

syntax on

保存并关闭文件

现在重新打开文件,突出显示语法。

Source here

相关问题