[英]VIM how to add certain html tags to the start or end of a line?
using... 2,40s/^/foo
I can add stuff to the start of line(s) in VIM. 使用... 2,40s/^/foo
我可以在VIM的行首添加内容。
using... 2,40s/$/foo
I can add stuff to the end of line(s) in VIM. 使用... 2,40s/$/foo
我可以在VIM的行末添加内容。
My question is... How can I add certain html tags to the end or start of a line in vim? 我的问题是...如何在vim中将某些html标签添加到行的末尾?
Example.. 例..
2,40s/$/</li>
- This command does not work. 2,40s/$/</li>
-此命令不起作用。 I can add <li>
to the end or start, but when I add '/' to it making the closing tag </li>
it doesn't allow it. 我可以将<li>
添加到末尾或开始,但是当我在结束标记</li>
添加'/'时,它是不允许的。
I also came across this problem when trying to add 2,40s/^/  to the start of some lines. 当尝试在某些行的开头添加2,40s / ^ /&nbsp时,我也遇到了这个问题。 The '&' character breaks the replace. “&”字符中断替换。
Is it possible to be able to add certain tags to vim lines, such as </li>
or & anything? 是否可以向vim行中添加某些标签,例如</li>
或&?
You need to escape special characters like / and & with \\ 您需要使用\\转义特殊字符,例如/和&
Example: 例:
2,40s/^/<pre>
2,40s/$/<\/pre>
2,40s/^/\
If you don't want to escape slashes you can use custom delimiter, in this case # : 如果您不想转义斜线,可以使用自定义定界符,在这种情况下为# :
2,40s#$#</pre>
The other approach would be to use visual block mode with Ctrl V , select all the line, then use A , type your tag </foo>
, then ESC . 另一种方法是在Ctrl V中使用可视块模式,选择所有行,然后使用A ,键入标签</foo>
,然后输入ESC 。
It will add </foo>
at the end of every line. 它将在每行末尾添加</foo>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.