加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何使用vim和插件快速添加所有行的html属性和值?

发布时间:2020-12-15 22:54:27 所属栏目:安全 来源:网络整理
导读:我的口碑:debian8. uname -aLinux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux 这是我的基本文件. home help variables compatibility modelines searching selection markers indenting reformatting folding ta
我的口碑:debian8.

uname -a
Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux

这是我的基本文件.

home 
help 
variables 
compatibility 
modelines 
searching 
selection 
markers 
indenting 
reformatting 
folding 
tags 
makefiles 
mapping 
registers 
spelling 
plugins 
etc

我想创建一个html文件,如下所示.

<a href="home.html" id="home">home</a>
<a href="help.html" id="help">help</a>
<a href="variables.html" id="variables">variables</a>
<a href="compatibility.html" id="compatibility">compatibility</a>
<a href="modelines.html" id="modelines">modelines</a>
<a href="searching.html" id="searching">searching</a>
<a href="selection.html" id="selection">selection</a>
<a href="markers.html" id="markers">markers</a>
<a href="indenting.html" id="indenting">indenting</a>
<a href="reformatting.html" id="reformatting">reformatting</a>
<a href="folding.html" id="folding">folding</a>
<a href="tags.html" id="tags">tags</a>
<a href="makefiles.html" id="makefiles">makefiles</a>
<a href="mapping.html" id="mapping">mapping</a>
<a href="registers.html" id="registers">registers</a>
<a href="spelling.html" id="spelling">spelling</a>
<a href="plugins.html" id="plugins">plugins</a>
<a href="etc.html" id="etc">etc</a>

每行都添加了href和id属性,其值是行内容粘贴.html和行内容本身相应的.

如何使用vim和插件快速添加所有行的html属性和值?
sed,awk,sublime text 3都欢迎解决问题.

解决方法

如果你确定内容,sed是最好的解决方案(这里简单而且非常快),如果不是需要一些复杂性,awk可以更好地对待它:

awk '
   {
   # change special char for HTML constraint 
   Org = URL = HTML = $0
   # sample of modification
   gsub( / /,"%20",URL)
   gsub( /</,"%3C",HTML)

   printf( "<a href="%s" id="%s">%s</a>n",URL,Org,HTML)
   }
   ' YourFile

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读