Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there different between single quote and double quote in vim command mode?

Tags:

vim

In my vim, I can use :%!sed "s/^/ /", got the wrong output when I use :%!sed 's/^/ /' .

sed: -e expression #1, char 0: no previous regular expression

Is there differences between single quote and double quote in vim command mode? In my sed, single quote is the same as double quote.

$ echo "wha012" | sed  's/w/haha/'
hahaha012

$ echo "wha012" | sed  "s/w/haha/"
hahaha012

my system is xp+vim 7.3 for windows.

In my system:
[1] "c://cygwin/bin/ash.exe"
[2] "c://cygwin/bin/bash.exe"
[3] "c://cygwin/bin/dash.exe"
[4] "c://cygwin/bin/sh.exe"

if i set set shell=\"c:\cygwin\bin\sh.exe"\ -f in _vimrc,i get the new wrong messages:

sed command can not found.

like image 736
showkey Avatar asked Nov 30 '25 19:11

showkey


1 Answers

Funny, when I try :%!sed "/^/ /" I get the same error message as when I use single quotes:

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 is also right that you can use vim to do things like this, but I assume you have simplified the example from what you were really trying to do.

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
like image 54
benjifisher Avatar answered Dec 02 '25 14:12

benjifisher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!