Vim - indent and syntax highlight broken after recover file
Asked Answered
D

5

5

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.

Depew answered 1/5, 2012 at 15:26 Comment(0)
B
8

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

:set filetype=c
Boomer answered 1/5, 2012 at 15:30 Comment(1)
Thanks for the answer. But can you explain why this happened despite running the swp file recovery.Mcginnis
T
2

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.

:)

Tortuosity answered 24/4, 2016 at 7:57 Comment(0)
S
1

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.

Saavedra answered 17/9, 2014 at 9:28 Comment(0)
C
0

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.
Candor answered 1/5, 2012 at 15:30 Comment(0)
R
0

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.

Revetment answered 2/5, 2012 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.