我想直观地标记几条线,然后用
包围整个范围。和
。经过大量摆弄后,我想出了这个似乎可以工作的替代命令:
:'<,'>s/^\(\_.*\)\%V/
\1< ;\/p>/
有没有更好的方法来做到这一点或者有人可以解释它为什么有效?
\_.
匹配每个字符,包括行尾。 ^
(行首)和 \%V
(匹配视觉范围)看起来表现得很奇怪。例如,文档建议您使用两个 \%V
来包围您的表达式,但这并不是必要的。不使用 \%V
或在开头仅使用一个来匹配整个缓冲区。删除 ^
会导致最后一行被单独匹配和替换。末尾的 $
接缝也是不必要的。
I wanted to visually mark a few lines and then surround the whole range with <p> and </p>. After a lot of fiddling I have come up with this substitute command that seams to work:
:'<,'>s/^\(\_.*\)\%V/<p>\1<\/p>/
Is there a better way of doing this or could someone explain why it works?
\_.
matches every characters including end-of-line. The ^
(start-of-line) and the \%V
(match visual range) seams to behave strange. For example the documentation suggest that you use two \%V
to surround your expression but that does not seams to be necessary. Using no \%V
or having only one at the start matches the whole buffer. Removing the ^
causes the last line to be matched and substituted separately. A $
at the end seams to be unnecessary also.
发布评论
评论(1)
1.使用surround vim
可以使用surround.vim,在视觉上模式:
s
Enter
例如
vat
(可视化选择“around”标签),s
周围有
...
细分:
p
2. 使用带有范围标记的 ex 命令
编辑:如果没有包围,您可以
3. 使用 yank 和 XML 文件类型插件插入寄存器内容:
或者更简单:
请注意,在 1 我的 XML fitetype 插件(我认为它是默认的)会自动提供了结束标记 (
),因此我们可以使用 Cr" 插入复制的内容--- 甚至无需离开插入模式!
1. Use surround vim
You can use surround.vim, in visual mode:
s<p
EnterE.g.
vat
(visual select 'around' tag),s<p
surround with<p>...</p>
Breakdown:
p
2. Use ex commands with the range markers
Edit: without surround you would be able to either
3. Use yank and XML filetype plugin inserting register contents:
Or much simpler:
Note that at 1 my XML filtetype plugin (I think it is default) automatically provided the closing tag (
</p>
) so we can just insert the yanked contents using C-r" --- without even leaving insert mode!