Vim把命令不允许双引号(因此没有转义序列)

时间:2021-11-27 20:05:34

I'm trying to run a script containing the Vim put command. I want a tab character in my string. The following code works, but the '\t' isn't interpreted due to the single quotes. When I replace the string with double quotes, the error messages seem to suggest that the first double quote ended the command. Code is...

我正在尝试运行包含Vim put命令的脚本。我想在我的字符串中使用制表符。以下代码有效,但由于单引号而未解释'\ t'。当我用双引号替换字符串时,错误消息似乎表明第一个双引号结束了命令。代码是......

let a=range(0,5)
for i in a
    put=i . '\t' . printf('\t%c', i)
endfor

Output is...

输出是......

0\t\t
1\t\t
2\t\t
3\t\t
4\t\t
5\t\t

Does anyone have any suggestions? I want the '\t' replaced with an actual tab character.

有没有人有什么建议?我希望'\ t'替换为实际的制表符。

1 个解决方案

#1


0  

Use double quotes instead of a literal string.

使用双引号而不是文字字符串。

let a=range(0,5)
for i in a
    put=i . \"\t\" . printf(\"\t%c\", i)
endfor

You can also use map() to shorten this up quite a bit:

你也可以使用map()来缩短它:

put=map(range(5), 'printf(\"%d\t\t%c\", v:val, v:val)')

For more help see: :h string and :h literal-string

有关更多帮助,请参阅:: h string和:h literal-string

#1


0  

Use double quotes instead of a literal string.

使用双引号而不是文字字符串。

let a=range(0,5)
for i in a
    put=i . \"\t\" . printf(\"\t%c\", i)
endfor

You can also use map() to shorten this up quite a bit:

你也可以使用map()来缩短它:

put=map(range(5), 'printf(\"%d\t\t%c\", v:val, v:val)')

For more help see: :h string and :h literal-string

有关更多帮助,请参阅:: h string和:h literal-string