简体   繁体   English

在VimScript中使用寄存器变量

[英]Using Register Variables in VimScript

I have the following code in vim Script(File name: file): 我在vim脚本中有以下代码(文件名:file):

:execute "normal /\This\<CR>gg"
:let i=1
:execute "normal nxxcwThat".@=i

I am executing this code on the following file(File name: out): 我正在以下文件(文件名:out)上执行此代码:

This is line 1
This is line 2

I am using the following run command: 我正在使用以下运行命令:

vim -s file out

And the output is: 输出为:

This is line 1
That 1 is line 2

I do not understand why is space getting printed between That and 1 . 我不明白为什么在That1之间打印了空格。
Also, I am slightly confused in how to use register variables when writing a vimscript. 另外,我在编写vimscript时如何使用寄存器变量有些困惑。 Could someone please explain? 有人可以解释一下吗?

That might be a bug. 那可能是一个错误。 But is there a reason, you are using the expression-register to access the variable? 但是是否有原因,您正在使用表达式寄存器来访问变量?

What works is to use, which looks more readable anyhow: 有效的方法是使用,无论如何它看起来更具可读性:

:execute "normal nxxcwThat".i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM