awk - How to do multi-line editing with vim while inserting text at the same vertical position?
伊谢尔伦
伊谢尔伦 2017-05-16 16:33:48
0
7
869

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>  
    
    你如何快速搞定??
    
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(7)
滿天的星座

Move the cursor to the upper left corner of home

<C-v>jj$x<ESC>

Move the cursor to before the first </a>

p
迷茫

Enter first

home
help
variables

Then use s 命令
输入 :%s/^/<a id="" href="">/g 回车
再输入 :%s#$#</a>#g Enter

小葫芦

After 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:

  1. Move the cursor to the "<" position of "" in the first line, Ctrl+v 进入列选择模式,jj$ 选中所有的 </a>,然后 d

  2. Move the cursor to the "home" line, Shift + v 进入行选择模式,jj 选中三行,然后 :right, and press Enter

  3. $ 把光标移至 "home" 结尾,按 p Paste

  4. gv 选中所有,然后 :left, press Enter

  5. The cursor is on the "h" of "home" in the first line, Ctrl + v 进入列选择模式,jj$y copy three lines

  6. 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

洪涛

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 ​​

世界只因有你
# 光标定位到第一行 a 标签
qa # 开始录制宏
<n>jyw # 复制要插入的文本
<n>kf>p # 回到对应到 a 标签,找到对应到位置,粘贴
j0 # 光标下移一行
q # 结束录制
2@a # 重播宏

# 上面的 <n> 是个数字,取决于你第一行 a 标签与第一行待插入文本之间的行数
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!