将通用缓冲区附加到 VI 中每行的末尾
我试图将通用缓冲区的内容添加到每行的末尾。我确信这相当简单,但是,一个小时的谷歌搜索却毫无结果。
这就是我的文件的样子
::露营要带的东西
--匹配
--帐篷
--睡袋
--充气床
--柴火
--野营炉
--煎锅
我想在每行末尾添加“::携带露营的东西”。
这是我到目前为止已经弄清楚的。
- /:: ->带我到有问题的行
- Y ->将整行拉入通用缓冲区
- 我尝试过 :%s/$/\p ->这会在每行末尾添加一个“p”。
我的问题是第 3 步。如何告诉“搜索和替换命令”使用“p”(通用缓冲区的内容)而不是“p” >”角色
非常感谢您的帮助。
I'm trying to add the contents of the general buffer to the end of every line. I'm sure this is fairly simple, however, an hour of google searches have lead me nowhere.
This is what my file looks like
::Things to bring camping
--matches
--tent
--sleeping bags
--inflatable bed
--firewood
--camping stove
--skillet
I want to add "::Things to bring camping" to the end of every line.
This is i have figured out so far.
- /:: -> brings me to the line in question
- Y -> yanks the entire line to the general buffer
- I tried :%s/$/\p -> this added a "p" to the end of every line.
My problem is with step 3. How do I tell the "search and replace command" to used the "p" (the contents of the general buffer) instead of the "p" the character
Thank you so much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只是一个建议:如果您尝试使用宏来执行此操作,您将能够使用“p”来添加通用缓冲区的内容。
Just a suggestion: If you try doing it with a macro, you will be able to use 'p' to add the contents of the general buffer.
抱歉,我必须进入 vim 才能找到答案。
在命令模式下复制整行的方法是:
^r "
(即 CTRL 和 r,然后是 " )
这应该将您拉入的整行粘贴到搜索和替换命令中
Sorry, I had to go into vim and find out.
The way to copy your entire line while in command mode, is:
^r "
(that's CTRL and r, then " )
That should paste the entire line you yanked into your search and replace command
对于第三步,您应该使用 ctrl-Ra,而不是 \p。按住 Ctrl 键并键入大写“R”,继续按住 Ctrl 键并键入小写“a”。
对于包含多个单词的行,请使用 ctrl-R-" 代替。
For step three, instead of \p, you should use ctrl-R-a. Hold down the control key and type an uppercase "R", continue holding control, and type a lowercase "a".
For a line with multiple words, use ctrl-R-" instead.
我同意使用宏——它们非常强大。
在本例中,我采用了您的列表示例并将其放置在第一个冒号处。
我使用 y$ 来获取缓冲区中该行的剩余部分。
然后我录制了宏 - 我选择了 1。
q1
j$pq
然后您可以为列表中任意数量的行调用它。例如10@1
I agree with using a macro - they're very powerful.
In this case I took your list example and positioned it at the first colon.
I used y$ to grab the remainder of the line in the buffer.
Then I recorded the macro - I chose 1.
q1
j$pq
Then you can call it for any number of rows in your list. E.g. 10@1
学到了一些东西来解决这个问题...
\= 表示接下来是要计算的表达式,并且 getreg() 调用获取寄存器的内容,默认情况下是“通用缓冲区”,因为它过去被调用六.
Learned something figuring this one out ...
The \= says that what follows is an expression to be evaluated, and the getreg() call gets the contents of the register, by default the "general buffer" as it used to be called by vi.