I'm using a plugin which can show the minimap for the file I'm editing. The plugin can only works with
utf-8. Does anyone know how to dynamically/temporarily change the encoding in Vim, so I can make the minimap work by temporarily set the encoding to utf8?
You can change the encoding of a loaded buffer simply by setting
'fileencoding' and then saving the file:
:set fileencoding=utf-8 :w
Hopefully this will allow your plugin to work, and then if necessary you can change the encoding back afterwards using the same method. You could probably also set up a
BufDelete autocommand to automatically change the encoding back when you are done with the buffer.
However, note that changing the encoding is not necessarily a reversible operation, and it's possible that changing it to a new encoding and then back again will result in data loss.
You also ask in the comments about setting a fallback option. This is what the
'fileencodings' option (plural, with an
s!) is used for. Setting it to e.g.:
will instruct Vim first to try reading files with big5, and if that fails, try utf-8 next. You can add as many comma separated encodings as you like to the setting; if none of these succeed without error, Vim will use the value of
'encoding' for reading the file.