The following document already exists
<a id="" href=""></a>
<a id="" href=""></a>
<a id="" href=""></a>
The system clipboard contains the following content:
home
help
variables
Needs to be inserted at the 15th position of each line to form the following format
<a id="" href="">home</a>
<a id="" href="">help</a>
<a id="" href="">variables</a>
如果vim不行,用awk可以吗?
This answer is not acceptable,
Enter first
home
help
variables
Then use the s
command
Enter :%s/^/<a id="" href="">/g
Press Enter
and enter again :%s#$#</a>#g
Enter
If I go further, I need to start from this basis
<a id="" href="">home</a>
<a id="" href="">help</a>
<a id="" href="">variables</a>
形成下面的
<a id="home" href="">home</a>
<a id="help" href="">help</a>
<a id="variables" href="">variables</a>
你又如何办?
再走远一点
<a id="home" href="home.html">home</a>
<a id="help" href="help.html">help</a>
<a id="variables" href="variables.html">variables</a>
你如何快速搞定??
滿天的星座2017-05-16 16:35:48
Move the cursor to the upper left corner of home
<C-v>jj$x<ESC>
Move the cursor to before the first </a>
p
迷茫2017-05-16 16:35:48
Enter first
home
help
variables
Then use s
命令
输入 :%s/^/<a id="" href="">/g
回车
再输入 :%s#$#</a>#g
Enter
高洛峰2017-05-16 16:35:48
After looking at your requirements, I think you may need the vim-snippets plug-in
PHP中文网2017-05-16 16:35:48
For the first requirement, there is no need to replace it, it can be achieved like this:
The picture is relatively large. If it cannot be loaded, here is the original address
Operation sequence:
Move the cursor to the "<" position of "" in the first line, Ctrl+v
进入列选择模式,jj$
选中所有的 </a>
,然后 d
Move the cursor to the "home" line, Shift + v
进入行选择模式,jj
选中三行,然后 :right
, and press Enter
$
把光标移至 "home" 结尾,按 p
Paste
gv
选中所有,然后 :left
, press Enter
The cursor is on the "h" of "home" in the first line, Ctrl + v
进入列选择模式,jj$y
copy three lines
gg$
光标移至第一行末尾,然后 p
The second requirement is the same, just cut id=""
the second quotation mark and the following content. The third requirement is that I can’t think of a better way at the moment
PHP中文网2017-05-16 16:35:48
You can use Bash+Sed to process it, but it’s like processing it in a programming language
#! /bin/bash
i=1
rm sd.f
cat sd.in | while read LINE
do
echo "${i}s/>/>${LINE}/" >>sd.f
#echo "${i}s/id=\"/id=\"${LINE}/" >>sd.f #第二次处理
#echo "${i}s/ref=\"/ref=\"${LINE}.html/" >>sd.f #第三次处理
((i++))
done
#cat sd.f
sed -f sd.f test.txt
Remarks: test.txt is the source file to be processed, and sd.f is the file generated by the program to store the sed processing command. sd.in is the stored variable value, namely home, help... three values
世界只因有你2017-05-16 16:35:48
# 光标定位到第一行 a 标签
qa # 开始录制宏
<n>jyw # 复制要插入的文本
<n>kf>p # 回到对应到 a 标签,找到对应到位置,粘贴
j0 # 光标下移一行
q # 结束录制
2@a # 重播宏
# 上面的 <n> 是个数字,取决于你第一行 a 标签与第一行待插入文本之间的行数