I'm using Vim (GVim, to be precise) under Windows 8 and I want to compile with the usual :!g++ %, but the name of the directory where my file is stored has accents, and Vim seems to have problems with them.

Here is the result of invoking :!g++ "%" (Vim does not seem to add the quotes around the current file path nor escapes spaces):

Invoking command uses wrong encoding

For the sake of clarity, the full path to the file shown is E:\Programación\Problemas algoritmos\(ns) ACM-ICPC Live Archive 2088 - Entropy.cpp

When I use Vim (instead of GVim), the accents seem to be handled properly, but it still adds a \ before ( and ), so the invoked command looks like

g++ "E:\Programación\Problemas algoritmos\\(ns\) ACM-ICPC Live Archive 2088 - Entropy.cpp"

Running these commands

:set encoding?
:set termencoding?

In Vim shows


But in GVim shows


How could I solve it?


I have already tried with the following lines in _vimrc:

set encoding=latin1
set termencoding=cp850

Looks like the real problem is not with accents but with parentheses. For example, it works with áéíóú.cpp but not with (a).cpp

  • By seting these options in your vimrc, of course.
    – romainl
    Commented Dec 1, 2013 at 7:01
  • @romainl Oh, I forgot to add that I already tried setting the encoding and termencoding as in Vim but it doesn't work Commented Dec 1, 2013 at 14:29
  • You tried setting termencoding to what in your vimrc? You put "set termencoding=cp850" in there and nothing changed?
    – Ben
    Commented Dec 1, 2013 at 18:34
  • @Ben Please see my edit. Looks like the real problem is with parentheses Commented Dec 2, 2013 at 22:15
  • Since the problem seems to be with parentheses, it's possible you need to call shellescape() on the filename. You may also have a problem with one of 'shellxquote', 'shellcmdflag', 'shell', or 'shellxescape' options. I THINK the defaults should work here. You can try manually escaping with ^ instead of \ if nothing else works.
    – Ben
    Commented Dec 2, 2013 at 23:16

1 Answer 1


I think the correct way to resolve this would be to set your termencoding in your .vimrc. However if you truly cannot get that working then it may be possible to work around this from the other end. You can set the encoding of your cmd.exe shell using the chcp command. For example this might work, but I have not tested:

:!chcp cp1252 & g++ "%"

Codepage 1252 is a superset of ISO-8859-1 (latin1) which your Vim is apparently using for encoding.

  • 1
    Please see my edit. Running chcp as you suggested gives "Invalid parameter format" Commented Dec 2, 2013 at 22:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .