Open a file in a Chinese directory. As long as the current directory of GVIM is not the Chinese directory or the file name is Chinese, enter :!%
in the command mode, this window will pop up and an error will be reported... English file names or English paths are no problem.
This seems to have nothing to do with Chinese or English, let’s take a look at the two screenshots:
According to your description, I operated a file with a Chinese file name and an English file name in sequence, and the results displayed were the same.
The key is
:!%
命令到底是什么意思。:!
是在 vim shell 里执行一个 shell 命令,而%
指代当前的文件名于是你的操作等于把文件名当作一个 command 来执行了,那么不管是中文还是英文都会报command not found
, which is the "system cannot find the specified path" you see under windows.I don’t know if you type
:!%
命令的目的是什么呢?如果是为了打开文件,那么可以:!open %
. This can open the file content in the current buffer under Mac. As for windows, I am not sure.gvim will send characters to the system in utf-8 format by default. Refer to h:termencoding
In your case, the Chinese characters in utf-8 are sent to the system cmd, and then displayed through cp936 encoding. So the display is garbled.
You can test it like this to verify: set encoding=cp936 to force cp936 display; then !%, execute the file, the garbled file name popped up by cmd is consistent with the content you force to display
I recently discovered a good way. It was clear before that the CMD window was "cp936" and the file name sent by GVIM was "UTF-8".
So, use GVIM's
iconv()
function to convert the "UTF-8" inside GVIM into "cp936" and pass it to CMD. In this way, the previous problem can be solved.I can currently use this sentence to complete it:
You can also have other functions with slight modifications.
The main idea comes from: http://www.oschina.net/code/snippet_574132_13357