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>
你如何快速搞定??
Move the cursor to the upper left corner of home
Move the cursor to before the first
</a>
Enter first
Then use
s
命令输入
:%s/^/<a id="" href="">/g
回车再输入
:%s#$#</a>#g
EnterAfter looking at your requirements, I think you may need the vim-snippets plug-in
Move the cursor to the first one
</a>
之前:<c-v>jjjp
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
Pastegv
选中所有,然后:left
, press EnterThe cursor is on the "h" of "home" in the first line,
Ctrl + v
进入列选择模式,jj$y
copy three linesgg$
光标移至第一行末尾,然后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 momentYou can use Bash+Sed to process it, but it’s like processing it in a programming language
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