VIM:如何将search / replace命令添加到vimrc并映射到快捷方式 [英] VIM: how to add search/replace command to vimrc and map to a shortcut

查看:101
本文介绍了VIM:如何将search / replace命令添加到vimrc并映射到快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个搜索/替换命令,我发现自己在vim中经常运行以清理html代码,以便我可以在线复制/粘贴。命令是:

 :%s!<!\& lt; !>!\& gt!!g 

我想要一种方法,我可以映射两者这些命令一起运行...我在vimrc中做了一些搜索如何使用:map 命令,但是我看不出如何组合两行进入单个命令(或单个笔画序列)运行的单个命令。



谢谢!

解决方案

您可以将命令放在一条单独的行上,用条形分隔。

 :%s!<!\& lt;!g |%s!>!\& gt;!g 

但是您必须在地图中转义它命令

 :map&F3 :%S< \&安培; LT; g\ |:!!!%S取代; \&安培; GT; G< CR> 


I have two search/replace commands that I find myself running in vim fairly often to clean up html code so I can copy/paste it online. The commands are:

:%s!<!\&lt;!g
:%s!>!\&gt;!g

I wanted a way I could map both of these commands to be run together ... I did some searching for how to use the :map commands in vimrc, however, I can't see how to combine the two lines into a single command that is run with a single keystroke (or a single sequence of strokes).

Thanks!

解决方案

You can put the commands on a single line separated with a bar.

:%s!<!\&lt;!g|%s!>!\&gt;!g

But you'll have to escape it in the map command

:map <F3> :%s!<!\&lt;!g\|:%s!>!\&gt;!g<CR>

这篇关于VIM:如何将search / replace命令添加到vimrc并映射到快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆