在我的 vim 中,我可以使用:%!sed "s/^/ /"
,当我使用时得到错误的输出:%!sed 's/^/ /'
.
sed: -e expression #1, char 0: no previous regular expression
vim命令模式下单引号和双引号有区别吗?
在我的 sed 中,单引号与双引号相同。
$ echo "wha012" | sed 's/w/haha/'
hahaha012
$ echo "wha012" | sed "s/w/haha/"
hahaha012
我的系统是 xp+vim 7.3 for windows。
在我的系统中:
[1]“c://cygwin/bin/ash.exe”
[2]“c://cygwin/bin/bash.exe”
[3]“c://cygwin/bin/dash.exe”
[4]“c://cygwin/bin/sh.exe”
如果我设置set shell=\"c:\cygwin\bin\sh.exe"\ -f
in _vimrc
,我收到新的错误消息:
找不到 sed 命令。
有趣的是,当我尝试时:%!sed "/^/ /"
我收到与使用单引号时相同的错误消息:
sed: 1: "/^/ /": invalid command code /
(This line replaces the content of my file.) I expect to get an error message there because, as @Birei pointed out, you left out the sed s command. This works as expected, with either single or double quotes:
:%!sed "s/^/ /"
@Birei 也是正确的,你可以使用 vim 来做这样的事情,但我假设你已经简化了你真正想做的事情的例子。
To answer the original question, Vim uses single quotes for literal strings. The only special character in a literal string is ' itself. Strings delimited with double quotes use \ to denote special character, such as `"\<Esc>".
:echo 'a''b' == "a'b"
:help expr-string
:help literal-string
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)