On Thu, Dec 25, 2025 at 01:32:54PM -0800, American Citizen wrote:
> Ted:
> 
> I am using vim, but when I attempt to write the UTF-8 file which I saved
> from the internet browser cut and paste command, into ascii format, vim
> fails with a curious error

UTF-8 works well in Vim. You just have to make sure it is properly
enabled in your environment. In fact, I am using Vim as my E-mail editor
for Mutt and I regularly include UTF-8 characters for various reasons
such as writing the degrees sign when I say that the high for today is 45°F.

If using GVim as a GUI, then you just need to make sure that (G)Vim is
configured for utf-8. If using Vim from a terminal, then you should also
make sure your terminal environment is also configured for UTF-8. Some
distributions like Fedora will already have done this for you. Others
like Arch expect for you to do this as part of the system set-up. Check
the output of the "locale" command to see if it contains UTF-8. You
should see "LANG=en_US.UTF-8" in the list of values or whatever's
appropriate for your native language. If it's not set, then you'll need
to add:

export LANG=en_US.UTF-8

To your shell's start-up script and maybe also modify the encoding
setting in your Terminal software if it's not already UTF-8. Once the
terminal is set-up, then add the following line to your .vimrc file:

set encoding=utf-8

With this, both Vim and GVim will support full UTF-8 encoding and it
should display correctly while in the terminal, over SSH, or GUI. Also,
if you ever have to save files in a different encoding, it's recommended
to keep encoding set to utf-8 as it allows the full repetoire of
characters in Vim and will display correctly on the terminal, but set
fileencoding instead of encoding when loading/saving the file. Vim will
convert on read/write. You can also use ++enc= with the :write or :sp
commands (and friends) to tell it at that time what the file encoding it
and it will convert it to/from UTF-8 while editing the file.

> 
> vim command:
> 
> :write ++enc=ASCII my_ascii_file.txt
> 
> I get the following error:
> 
> "my_ascii_file.txt" E513: Write error, conversion failed (make 'fenc' empty
> to override)
> WARNING: Original file may be lost or damaged
> don't quit the editor until the file is successfully written!
> Press ENTER or type command to continue

This is expected. You are telling Vim that it's only allowed to write
characters that reside withing the 128 ASCII characters, but your file
has non-ASCII characters in it. It would have to remove those characters
to save it. You'd have to save it with an encoding like UTF-8 that
includes them to save the file without loss.

> 
> And trying to internally set the values of encoding and file encoding seems
> to work
> 
> :set encoding=ascii
> 
> :set fileencoding=ascii
> 
> except when you double check the encoding, it stays at utf-8
> 
> but the fileencoding appears to be changed to the new value=ascii
> 
> But then when you attempt to overwrite the file or write to a new file, vim
> throws errors again
> 
> "new_file.txt" E513: Write error, conversion failed (make 'fenc' empty to
> override)
> WARNING: Original file may be lost or damaged
> don't quit the editor until the file is successfully written!
> Press ENTER or type command to continue
> 
> So I am unable to get linux vim version 9.1.83 to work to change the
> encoding.
> 
> I had to actually use notepadqq to paste the browser text and then set the
> encoding to ascii and this seems to work.
> 
> I suppose you could pipe the file and let tr strip off the non-ascii
> characters ??? But this means going back in and manually comparing the two
> files, to see how to fix the omitted characters (if possible)
> 
> TexStudio crashed mysteriously when I turned off its internal file scanning
> so I had to set the option again.
> 
> Supposedly there is some tex sty code which allows UTF-8 to be used in a tex
> file. And yes, my editor settings under TexStudio IS UTF-8
> 
> I already have used up at least an hour of time on this problem as iconv
> doesn't really change a pure ascii file into a UTF-8 file and vim was
> failing me.
> 
> Randall
> 
> On 12/25/25 11:28, Ted Mittelstaedt wrote:
> > Open the regular textedit, paste into there, save, open the saved file in 
> > TexStudio
> > 
> > Ted
> > 
> > -----Original Message-----
> > From: PLUG <[email protected]> On Behalf Of American Citizen
> > Sent: Wednesday, December 24, 2025 7:40 PM
> > To: Portland Linux/Unix Group <[email protected]>
> > Subject: [PLUG] Ascii versus UTF-8 woes
> > 
> > Hi:
> > 
> > I have a set of tex files which are in pure ascii format. Unfortunately 
> > when I copy material from the internet (Mozilla Firefox browser) it is in 
> > UTF-8 format, not ascii. This appears to be standard behavior for the 
> > internet browsers.
> > 
> > When I paste the material into the tex document (using TexStudio) the paste 
> > goes okay. It only blows up when I try to save the newer file. The
> > UTF-8 characters cannot be saved in ascii format and for some bizarre 
> > reason Tex Studio wont' change the encoding to UTF-8 even though I have the 
> > option set that the editor is working with UTF-8 character set.
> > 
> > iconv won't work either, I do the "iconv -f ASCII -t UTF-8 input_file -o 
> > output_file and the file remains ascii.
> > 
> > Does anyone have an idea of how I can get TexStudio to wake up and change 
> > the file encoding on the current ascii file to UTF-8?
> > 
> > I cannot get iconv to change the ascii file to UTF-8, so I am stuck between 
> > the devil and the deep blue sea.
> > 
> > Randall
> > 
> > 
> > 

-- 
Loren M. Lang
[email protected]
http://www.north-winds.org/
IRC: penguin359


Public Key: http://www.north-winds.org/lorenl_pubkey.asc
Fingerprint: 7896 E099 9FC7 9F6C E0ED  E103 222D F356 A57A 98FA

Attachment: signature.asc
Description: PGP signature

Reply via email to