How to paste something between html tags in Vim?

我的未来我决定 提交于 2019-12-20 12:37:16

问题


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

回答1:


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.




回答2:


I usually just do vitp which visually selects the inner contents of the tag, then pastes over what is selected.

Works for me.




回答3:


remove the current content between the tags with the command

cit

that will 'change in tags' and once that content is gone, you can paste with middle click or if you need go back into command mode and use your normal p/etc.




回答4:


vitp should handle a linewise paste.




回答5:


You can press "v" for visual, then go to where the cursor is, and press p or P.



来源:https://stackoverflow.com/questions/2287031/how-to-paste-something-between-html-tags-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!