[英]Using bash calculator in a vim script - strange behaviour
Does anybody know why this works with bash calculator ( bc
) in vim
:有谁知道为什么这适用于vim
bash 计算器( bc
):
echo system ("echo 3+5 \| dos2unix \| bc -l") ---> output: 8
echo system ("echo 3/5 \| dos2unix \| bc -l") ---> output: .600000000000000
echo system ("echo 3*5 \| dos2unix \| bc -l") ---> output: 15
but this not:但这不是:
echo system ("echo 2^5 \| dos2unix \| bc -l") ---> output: 25
echo system ("echo 3^5 \| dos2unix \| bc -l") ---> output: 35
This is used under cygwin in Windows.这在 Windows 中的 cygwin 下使用。
What is the value of &shell
option? &shell
选项的值是什么? It must be /path/to/cygwin/bash
, not something ending with cmd.exe
.它必须是/path/to/cygwin/bash
,而不是以cmd.exe
结尾的东西。 The problem is that ^
is an escape character in windows cmd.exe
, so echo 2^5
is somewhat equivalent to echo 2\\5
resolving into echo 25
.问题是^
是 windows cmd.exe
的转义字符,因此echo 2^5
有点等同于echo 2\\5
解析为echo 25
。
If it is cmd.exe
add a line如果是cmd.exe
添加一行
set shell=/path/to/cygwin/bash
to your vimrc.到你的 vimrc。
Note though that echo 2^^^^5
resolving to echo 2^5
is somewhat strange (in plain cmd.exe
it is echo 2^^5
), but I saw very long discussion on vim-dev regarding escaping issues for cmd.exe
some time ago, so it may be one of them.请注意,虽然echo 2^^^^5
解析为echo 2^5
有点奇怪(在普通的cmd.exe
它是echo 2^^5
),但我在 vim-dev 上看到了很长的关于cmd.exe
转义问题的讨论cmd.exe
前一段时间,所以它可能是其中之一。 Should not happen on the most recent vim (or it is a bug).不应该发生在最近的 vim 上(或者它是一个错误)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.