VIM: Certain .c files opening without syntax highlighting
Asked Answered
E

1

8

I have some .c files that don't automatically highlight in vim. This problem only recently started. I have not edited my .vimrc file:

set number
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>
set ignorecase
syntax on
filetype plugin indent on
nnoremap <C-H> :Hexmode<CR>
inoremap <C-H> <Esc>:Hexmode<CR>
vnoremap <C-H> :<C-U>Hexmode<CR>
au BufWinLeave * mkview
au BufWinEnter * silent loadview
set tabpagemax=15
set wrap

The weird thing is when I open a file that doesn't automatically highlight, and type :set syntax=C, it works, but if I reload my .vimrc file using :so ~/.vimrc the highlighting goes away. This doesn't happen with other .c files.

Evvoia answered 28/7, 2011 at 17:5 Comment(0)
F
10

Try to remove all files in ~/.vim/view (eventually make a backup before deleting it).

Feathery answered 28/7, 2011 at 17:9 Comment(5)
Thank you. This resolved it. What do the files in the view folder do?Evvoia
Not totally sure, but for each source file there is a view file which contains a few informations for the editor. For example, the cursor position in the source file is stored, so when you reopen the file with vim, it jumps to the last edited location (which is pretty usefull). Also, if you use folding, folding configuration is stored there. If a file is corrupted, then vim won't show syntax highliting.Feathery
Googling "~/.vim/view" sucks, so for future questioneers: look at :help 'viewdir' and :help :mkview.Cabriolet
in macos the directory you have to remove is ~/.vimviewsBoulanger
I usually delete the single corrupted file in the viewdirGlassman

© 2022 - 2024 — McMap. All rights reserved.