Question

I was editing a file with vim. I started another vim to edit the same file, it said that the /tmp/file.swp exits, press "R" to recover it. I chose to recover. But after that, syntax highlight didn't work on that file (other files still ok). I tried :syntax on and some commands but not worked.

Was it helpful?

Solution

You may try to use the following command to specify the type type. For example for c file:

:set filetype=c

OTHER TIPS

I just solve it, in a simple way.

I find the folder which ~/.vim/view/ and remove the record about the py file which i just recovered...

cd ~/.vim/view && ls -alh | grep filename_1 | awk '{print $9}' | xargs rm

You can change that as you like ... just a demo.

:)

I had to recover a vim buffer after a sudden crash. Whilst the file was correctly recovered, I could not say the same for the syntax highlighting. (I am pretty sure this is not language-dependent, but for completeness sake my file was a python script.)

To my knowledge this issue is often due to either sessions, as stated in this similar question, or syntax highlighting which was incorrectly loaded. However vim views also affect how the file is displayed in the editor. This is especially true for those, like me, who tend to automatise the loading of previously stored views. Following this hunch I deleted my stored view file and solved the problem.

Please note this solution obviously comes at a cost: the file will be opened with a fresh view, i.e. no previous layouts (cursor position, opened/closed fols, etc.) will be remembered by vim. This is pretty obvious but I thought I'd mention it nonetheless.

Might need to set the file type for the correct syntax:

" C syntax:
:set ft=c

" Java syntax:
:set ft=java

" Python syntax:
:set ft=py

" ... etc.

You can re-run the buffer open process to run all autocommands again by typing :e % which edits the current file. This will make all bufread* auto commands run and you'll get everything back. I believe they are deliberately disabled in case there's something bad in the recovered file and custom autocommands may do something bad with a corrupted file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top