Monday, December 7, 2020

Re: Changing encoding of an already loaded buffer

The actual "correct" way to "change" the encoding of a buffer is, I
believe, with the "++enc" option, added either to :e (e.g. `:e
++enc=utf8`) or several similar commands such as indeed :vi (`:vi
++enc=utf8`).

However I couldn't find a way to make it work with a file-less buffer,
such as your pipe example:

If I use `:e! ++enc=utf8` I'm given an «E32: No file name» error.

I thought of passing "%" of "#n" as the filename for :e (`:e ++enc=utf8
%`), but it doesn't work, I'm given a «E499: Empty file name for '%' or
'#', only works with ":p:h"» error (and indeed the `:h _%` stuff is
described as standing for "file names", not for the actual buffers).

Then I tried adding a filename, with `:file whatever`, but once that's
done :e! loads a new empty buffer named "whatever"...

So there doesn't seem to be a way to really reload (possibly with
different encoding options) the current buffer, only to reload the file
from which the current buffer was loaded, and so for file-less buffers
no way at all.

However under Linux and other systems there may well be a way to access
the buffer's file's descriptor (/dev/fd/0 ?), so it might work by
passing that as the filename.

And there's probably some other way by copying the text around.

By the way, apparently this also means that you can't even set the
encoding of a pipe that you haven't yet created, from the shell, since
to the best of my knowledge the only way to set the encoding of a file
from the shell, before opening it, is `vim +":e ++enc=<encoding>
<filename>"` (which actually means to open it from inside vim). But
maybe you can with some more intricate command.


I'm far from being Vim expert however, I might well be missing something
(or a lot).


And encoding stuff is in general quite a mess in Vim, I'll grumble about
it one time or another... :/


Cheers

--
--
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/07941846-edc4-431c-3889-0c7020254157%40tiscali.it.

No comments:

Post a Comment