Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change encoding for existing file with Vim

here is a subtitle file on http://subscene.com/subtitles/crank/farsi_persian/281992. if you download it you will see some codes like:

1
00:02:05,360 --> 00:02:07,430
åßÊæÑ¡ ãÇ åäæÒ ÏÇÑíã ãí ÑÎíã¿
ÎæÈå

2
00:02:07,600 --> 00:02:10,956
áíæÓ! ãÇ ÏÇÑíã í ÇÑ ãíäíã Èå ¿
æ Ïíå åí æÞÊ ãä Ñæ ÕÏÇ äãíÒäí

the thing i expect is:

1
00:02:05,360 --> 00:02:07,430
هكتور، ما هنوز داريم مي چرخيم؟
خوبه

2
00:02:07,600 --> 00:02:10,956
چليوس! ما داريم چي کار ميکنيم بچه ؟
و ديگه هيچ وقت من رو صدا نميزني

i reached it by changing the file extension from srt to txt, opening it with chrome browser, chenging encoding to arabic windows and re save file contents by select all text.

i have no idea how to do this with vim, or shell script. i tried :write ++enc=utf-8 russian.txt or set encoding or set fileencoding, but no luck.

thanks, mona

like image 482
Mona Avatar asked Mar 28 '13 12:03

Mona


1 Answers

in vim:

after loading your file, don't do any modification. then you could do:

:e ++enc=cp1256

To save in utf-8, just

:w ++enc=utf-8

or you could do it in shell:

iconv -cf WINDOWS-1256 -t utf-8 problem.srt -o correct.srt
like image 57
Kent Avatar answered Oct 01 '22 13:10

Kent