杜智超
杜智超

Reputation: 637

How can I use backslashes in variables in vim script?

If I define a variable in vim script:

let path = "E:\mainVersion\GameServer"

and then echo it:

echo path

But I get this :

E:mainVersionGameServer

I think maybe it's because the backslash is an special character. Here's my quertion:

  1. Why the backslash(\) disappear?
  2. How can I echo the entire variable?

Can you help me?

Upvotes: 1

Views: 387

Answers (2)

SibiCoder
SibiCoder

Reputation: 1496

Like in most languages, you can use backslash to escape those characters.

     :let path= "E:\\path\\subdirectory"

Upvotes: 1

Kent
Kent

Reputation: 195079

use single quote

let path = 'E:\mainVersion\GameServer'

then

echo path

another test:

let foo="a\nb" 
echo foo

output:

a
b

and:

let foo='a\nb'
echo foo

you will see: a\nb

With single quote those sequences will be ignored.

Upvotes: 3

Related Questions