Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Vim I can open the directory of an active file using this command:

:silent ! start %:p:h

However, if the directory contains special characters (like Scandinavian letters), I'm getting an error. Below is a link to an example.

The error says something like "Can't find the target. Please make sure you wrote it right and try again." (in Finnish). The directory in the above example is D:\ölöälä, but as you can see, the ö and ä-letters don't show properly in the cmd. I think that causes the error.

How can I solve this? I'm on 64-bit Win 7.

share|improve this question
I don't think I'll be able to help but are you able to type öä in Vim itself? – romainl Jan 1 '12 at 12:03
Yes. I have been using Vim quite a long time but this is the first time I encounter any problems with ö's and ä's. – martias Jan 1 '12 at 13:25
Looking around google gives me the impression that it's quite hard to use non-ASCII characters in cmd.exe. If Vim correctly sends the right characters with the right encoding to cmd.exe (which I think it does) you have probably encountered a serious limitation of cmd.exe. I see there are a number of alternatives, did you try any? Also, supposing you have it on your system, maybe iconv could help? – romainl Jan 1 '12 at 16:34
up vote 4 down vote accepted

This is a vim bug.

It's not a problem, contrary to what romainl says in a comment to the question, with cmd at all. It's nothing to do with cmd in fact. Both cmd and start are behaving as designed.

The problem is that vim is using UTF-8 (See :help unicode.) for storing and manipulating the command string, and is passing that UTF-8 string as-is to a programming API that doesn't accept UTF-8 in the first place. Specifically: It ends up passing the UTF-8 string to the CreateProcessA() function. But CreateProcessA() takes strings encoded in the Windows code page. vim should convert the string beforehand from UTF-8 to the appropriate code page (or to Unicode and call CreateProcessW() instead). But it doesn't.

As a consequence, the sequence of bytes in your UTF-8 pathname, as constructed by vim from %:p:h, is being treated by CreateProcessA() as if it were a sequence of bytes in the Windows code page. You can see the result.

There's probably no local fix for this. Using 8.3 names (:8) won't fix this at all. But fiddling with vim's encoding variable might ameliorate it to an extent (although it will affect more than just this, and isn't the correct way to address the problem). You'll have to talk to Bram Moolenaar. (Consulting the vim 7.3 bug list, I find that you can also talk to this person, although convincing M. Moolenaar that kikuchan is not alone is still a good idea.)

share|improve this answer
Thanks for this very good answer. I still think that not accepting utf-8 characters is a very serious limitation wether it's cmd.exe or a sub-process. And I also agree that it's a bit boneheaded to insist on sending utf-8 strings to commands that are know for not accepting it. – romainl Jan 2 '12 at 8:59
How many times do I have to say that this is nothing at all to do with cmd before it sinks in? The Win32 system API function takes the character sets that it is defined as taking. This is not a limitation, let alone a "serious" one, especially given the existence of the W() flavour of the API. – JdeBP Jan 2 '12 at 9:41
As far as I'm concerned you said it only once and I agreed and thanked you for it. What's wrong with you? An API method that doesn't support UTF-8 in 2012 is seriously useless IMO and the fact that Vim doesn't use an alternative method that supports UTF-8 is even worse. – romainl Jan 2 '12 at 11:00
Any wrongheadedness here is yours, because you did not do that, as can be quite clearly seen. I said it and in response you kept on blaming cmd. It also apparently hasn't sunk in that there is an API flavour that supports Unicode, even though I pointed that out as well. This continued daft "seriously" here is based upon either not paying attention or a foolish unwilliness to acknowledge that the A() flavour of the API is not "limited" or "useless" but has a well-defined purpose that is simply something else. – JdeBP Jan 2 '12 at 13:40
Here is how it went: 1. I quickly look around and see quite a lot of people having trouble sending utf-8 to cmd and no user-level solution. 2. You post a very good answer. 3. I thank you for that and I make a quick general remark about anything ("wether it's cmd.exe or a sub-process" please note the misspelled "whether") not supporting utf-8 AND I – romainl Jan 2 '12 at 15:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.