Tuesday, December 8, 2020

Re: Changing encoding of an already loaded buffer

On Tue, 8 Dec 2020 at 12:55, Bram Moolenaar <Bram@moolenaar.net> wrote:
>
>
> Albert Wik wrote:
> >
> > Right. The only way I've found is to use a temporary file.
> > Incidentally, the zsh shell makes that easy:
> > % gvim -f =(man llseek)
>
> Assuming that loading the text as latin1 didn't mess it up (since it's
> an 8 bit encoding it should be OK), then you can convert it to utf-8
> with:
> :set fencs=utf-8,latin1
> :%!iconv -f latin1 -t utf-8
>
> Vim might recognize the utf-8 encoding, if not set set 'fenc':
> :set fenc=utf8
>
> Hopefully that works.

Thanks a lot for the "%!"-idea! That's what I needed.

This works:
:set fencs=utf8
:%!cat
although "fenc" remains "latin1".

It is not appropriate to use "iconv -f latin1 -t utf8" (that does in
fact corrupt the data!) because the data is already in UTF-8, and that
is why it is not displayed properly in Vim (because Vim thinks it is
in Latin-1); in particular, the short dash character is shown as
"â<80><90>". When it is displayed properly, a "‐" is shown; putting
the cursor at it and doing "ga" reports that this is character number
0x2010.

Why does "set fencs=utf8" matter for the "%!cat" operation if Vim is
not going to change the "fenc" accordingly?

Cheers,
Albert.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CALPW7mREoMoWYG%2BW26d_vWPiD5bKhU-r5MvY8RSOE3YTj-KZvQ%40mail.gmail.com.

No comments:

Post a Comment