12

Windows 10, Emacs 25.

When I want to convert file from Windows-1251 to UTF-8 I use Notepad++.

Before convert:

enter image description here

convert:

enter image description here

after convert:

enter image description here

My question is: Is it possible this convert in Emacs?

3 Answers 3

11

One should use the command set-buffer-file-coding-system (C-x RET f), set the encoding, and then save the file.

Note that you may want to first revert-buffer-with-coding-system (C-x RET r) before performing the above step, if the file is opened with the wrong encoding in the first place.

1
  • 1
    This worked for me. It modified the buffer and I was able to save as UTF-8.
    – MattMS
    Commented May 2, 2018 at 2:50
5

The easiest way to do this is to:

  1. Type C-x RET c
  2. Select the desired coding system (in this case probably utf-8-dos)
  3. Pass C-x C-w as the command and pass the name of the file to write
3
  • Not help. File stay on "windows-1251"
    – Alex
    Commented Aug 1, 2017 at 16:10
  • @Alex sorry, I thought it was the other way around. I edited the answer to work for this case.
    – user12563
    Commented Aug 1, 2017 at 18:45
  • 1
    I try again, but it not help. Coding system not change to utf-8-dos
    – Alex
    Commented Aug 2, 2017 at 7:03
2

This should do the trick:

  1. Visit the file with C-x C-f.
  2. Revert opened buffer to the original file encoding (cp-1251 in this case) with M-x + revert-buffer-wth-coding-system.
  3. Use M-x + set-buffer-file-coding-system to set encoding to utf-8.
  4. Save the file.
1
  • 2
    this answer is similar to @xji 's answer. Commented Dec 12, 2018 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.