如何在 Vim 中的 html 标签之间粘贴一些东西? [英] How to paste something between html tags in Vim?

查看:31
本文介绍了如何在 Vim 中的 html 标签之间粘贴一些东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

p 粘贴当前行下方的内容,dit 删除 html 标签内的内容.如何在 html 标签中粘贴内容?

 也不在这里<p>我想在这里粘贴一些东西</p>不在这里

解决方案

按下Pp 的结果取决于你当时所选寄存器中的内容.如果您删除或猛拉一整行或多行(例如使用 ddYVd 命令),然后按 P 将在当前行上方的 line 插入寄存器的内容,而 p 将插入光标下方的行.

如果您删除或猛拉一段少于一行的文本(例如使用 Dyw 命令),则 P将直接在当前光标位置之前插入寄存器的内容,p 将直接插入光标后(即在同一行).

如果有帮助,您可以将逐行选择视为类似于 block html 元素(例如

),并将字符选择视为类似于内联 html 元素(例如span).

所以回答你的问题:这取决于.假设您在寄存器中有一行文本部分,您可能希望在执行粘贴操作之前将目标标记分成两行.在您的示例中,不是执行 dit 删除标记的内容,而是执行 cit 删除同一部分并进入插入模式.点击 return 一次,插入一个新行,然后 esc 返回到正常模式,然后 P 将你的 linewise 寄存器插入到行上方带有结束标记.

如果您不想将标签拆分为多行,则必须确保将按字符选择的内容拖入寄存器.然后你可以运行:

"_ditP

"_ 将文本删除到 黑洞 寄存器中,确保它不会覆盖默认寄存器中的内容.dit 删除标签的内容,P 将默认寄存器的内容粘贴到光标位置之前.

Pressing p pastes things bellow the current line, dit deletes things inside html tags. How do I paste something inside html tags?

    Nor here
<p>I want to paste something here</p>
    Not here

解决方案

The result of pressing P and p depends on what you have in the selected register at the time. If you delete or yank one or more entire lines (e.g. with dd, Y or Vd commands), then pressing P will insert the contents of your register on the line above the current line, whereas p will insert on the line below the cursor.

If you delete or yank a section of text less than a line (e.g. with the D, or yw commands), then P will insert the contents of your register directly before the current cursor position, and p will insert directly after the cursor (i.e. on the same line).

If it helps, you could consider the linewise selection as being analogous to block html elements (such as <div>), and characterwise selection as being analogous to inline html elements (such as span).

So to answer your question: it depends. Supposing you have a linewise section of text in the register, you would want to break the target tag onto two lines before doing the paste operation. In your example, rather than doing dit to delete the contents of the tag, do cit to delete the same section and go into insert mode. Hit return once, to insert a new line, then esc to go back into normal mode, then P to insert your linewise register above the line with the closing tag.

If you didn't want to split the tag onto multiple lines, you would instead have to make sure that you yanked a characterwise selection into the register. Then you could run:

"_ditP

"_ deletes the text into the black hole register, ensuring it doesn't overwrite what is in your default register. dit deletes the contents of the tag, and P pastes the contents of your default register before the cursor position.

这篇关于如何在 Vim 中的 html 标签之间粘贴一些东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆