[英]VIM: how to add search/replace command to vimrc and map to a shortcut
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. 我有两个搜索/替换命令,我发现自己经常在vim中运行以清理HTML代码,因此我可以在线复制/粘贴它。 The commands are: 命令是:
:%s!<!\<!g
:%s!>!\>!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). 我想要一种方法,我可以将这两个命令映射到一起运行...我做了一些搜索如何在vimrc中使用:map
命令,但是,我无法看到如何将两行合并为一个命令用单击键(或单个笔画序列)运行。
Thanks! 谢谢!
You can put the commands on a single line separated with a bar. 您可以将命令放在用条分隔的单行上。
:%s!<!\<!g|%s!>!\>!g
But you'll have to escape it in the map
command 但你必须在map
命令中将其转义
:map <F3> :%s!<!\<!g\|:%s!>!\>!g<CR>
If you are using this search/replace pattern to HTML encode entities, you might want to check out the unimpaired plugin . 如果您将此搜索/替换模式用于HTML编码实体,则可能需要查看未受损的插件 。 Amongst other things, this provides shortcuts for encoding and decoding XML, URL and C strings. 除此之外,它还提供了对 XML,URL和C字符串进行编码和解码的快捷方式。
:map <F3> :%s!<!\<!<cr>:%s!>!\>!<cr>
当然可以用你想要的任何键替换
我没试过,但是你能不能把它们放在由"<CR>"
分隔的同一行上吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.