How to change encoding for an already opened file? #2981
-
First, thanks A LOT to the micro devs for creating and maintaining it. A truly wonderful piece of software with a lot of care. I have files saved in various text encodings. I have a habit of opening them in the Midnight Commander mcedit and, in case it hasn't recognized the encoding correctly, adjusting it quickly with a hotkey, e.g. "Alt-e, c" for a quick switch to UTF-8. Now I'm in the process of migrating to micro from mcedit. I see micro mentioning "utf-8" in the status line, but I haven't found a way of changing it, if the file is not UTF-8. Does micro have a key binding for that? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
You can change the encoding with a command like
{
"<Alt-e><c>": "command:setlocal encoding utf-8,command:reopen"
} |
Beta Was this translation helpful? Give feedback.
-
@Andriamanitra Thanks much for your answer! I particularly liked that you used my mentioned key combination in your sample :) Is this a regular level of friendliness and attention to details in the micro community? :) Let me try the commands you suggest. In the meantime: where in the documentation a regular user could find this? I really struggled searching for anything like "encod". Also, those "set" and "setlocal" — I'm trying to study them a bit by calling "help" on them, but micro simply tells "Sorry, no help for set/setlocal". What help could I read on them? |
Beta Was this translation helpful? Give feedback.
-
One more thing: you used the term "current buffer". What does that mean in micro? A full opened file, or something like a selection, or even the clipboard contents?.. |
Beta Was this translation helpful? Give feedback.
-
You're welcome! Unfortunately the community is somewhat inactive which can make it difficult to get answers to questions, but I try to do my part to help where I can.
Micro has tabs, each of which can be split (with |
Beta Was this translation helpful? Give feedback.
You can change the encoding with a command like
set encoding utf-16le
(to change the global setting) orsetlocal encoding utf-8
(to change the setting for current buffer). I think the only times micro uses the encoding is when opening or saving a file – it won't automatically re-interpret the current file with the selected encoding. If you want to do that you can set up a keybinding that runs two commands sequentially:$HOME/.config/micro/bindings.json
: