Changing text encoding in Emacs

March 4, 2009

I’m posting this mostly so I’ll know where to look the next time I forget…

This is definitely the king of obscure Emacs key combinations. To change the encoding of an existing file, use C-x RET f <encoding> RET.

Tab-completion works for the encoding. “utf-8” is the one I use most often, but “unix” and “dos” are also useful.

To make Emacs open files in UTF-8 per default, use the following snippet in .emacs:

(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: