2

Gvim 8.2 displays "Can't open file for writing" with a windows files that have a Unicode colon in the file name. Notepad, Wordpad, LibreOffice all work.

JerryD
  • 23
  • 2
  • 3
    Welcome to Vi and Vim! There are a couple unicode colons, which code point is it exactly? – Jake Grossman Sep 28 '20 at 03:52
  • OS Windows forbids colons in file names. Please, please, don't!! – Matt Sep 28 '20 at 06:29
  • 1
    Are you sure this actually works in other editors? colons are used to denote alternate data streams on Windows. So this might actually have unwanted consequences. I would recommend not to use this. – Christian Brabandt Sep 28 '20 at 07:28
  • I just tested wordpad and another text editor. Both wouldn't save, and popped up an error saying invalid file name, when trying to save a file with a : in the file name. – Herb Sep 28 '20 at 19:19
  • Regarding Jakes note: What code point is it? Open the file in question, then hit "%p. This will paste the file name. Move the cursor to the problematic character and hit ga. This will display the character information. Update your question with that information. – Ralf Sep 29 '20 at 07:29
  • 1
    I use Unicode colon FF1A – JerryD Sep 29 '20 at 15:47
  • 2
    Jerry, add this info to the question itself (hit the small „edit“). Here in the comments it is difficult to find. – Ralf Sep 29 '20 at 17:30
  • I just placed "set encoding=utf-8" at the top of my _vimrc file and it worked. I edited and wrote the file out and then did the same with with Notebook, Wordpad and LibreOffice, all worked.

    Thanks, jerryd

    – JerryD Sep 29 '20 at 22:07
  • @JerryD Great we got that sorted out. Please accept the answer by clicking the grey checkmark. – Ralf Sep 30 '20 at 06:21

1 Answers1

4

You mentioned in the comments, that the "unicode colon" is 0xFF1A. According to codetable.net this is a "Fullwidth Colon".

  • ":" (Fullwidth Colon)
  • ":" (normal colon)

I tested files with this character in its name on

  • Vim on Linux -> OK
  • Vim in Git Bash on Windows (MSYS2) -> OK
  • Vim on Windows -> NOT OK

I only have a rather old 8.1.2188 available on Windows 10. On loading the file the Fullwidth Colon was replaced by a normal colon. So in fact Vim is not editing the file given as parameter (or selected via file dialog or opened via drag and drop).

So this is not the problem you see, but there is something wrong.

The problem in this case is, that the encoding of Vim internally is "latin1", a single-byte character set. So the file name is converted to latin1 and this results in replacing the Fullwidth Colon with a normal colon.

I changed the internal character set by adding

set encoding=utf-8

as the first line of my vimrc.

Just try this. After you restarted Vim you can execute

:set encoding?

to validate that the encoding is really "utf-8". If not, something is resetting it -- maybe you have a superfluous set nocompatible.

With encoding set to utf-8 I can load and save the file containing the Fullwidth Colon in the name.

Ralf
  • 9,197
  • 1
  • 11
  • 30
  • Oh I see. I think, the default encoding setting for Windows should in my opinion always be UTF-8, but IIRC, Bram doesn't want to change this for backwards compatible reasons. – Christian Brabandt Sep 30 '20 at 07:38