Vim - 如何使您自己的映射可重复? [英] Vim - How to make your own mapping repeatable?

查看:23
本文介绍了Vim - 如何使您自己的映射可重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 vimrc 中有以下映射:

I have following mappings in my vimrc:

nmap <Leader>h1 yyp<c-v>$r=
nmap <Leader>h2 yyp<c-v>$r-

我想用重复h1/2.

I'd like to repeat <Leader>h1/2 with .

Tim Pope 的 repeat.vim 插件如下使用线

There exist the repeat.vim plugin by Tim Pope with following usage line

silent! call repeat#set("\<Plug>MyWonderFulMap", v:count)

我尝试通过以下方式使用它:

I tried using it in the following way:

nnoremap <silent> <Plug>MyWonderfulMap :normal yyp<c-v>$r=
silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
nmap <Leader>h1 <Plug>MyWonderfulMap

它不起作用.

我知道这不是一个严重的复杂问题,但是,我有兴趣将 repeat.vim 用于自己的映射.

I know it is not a serious complication, however, I am interested to use the repeat.vim for own mappings.

推荐答案

repeat#set() 调用必须在映射调用之后进行,而不仅仅是一次映射定义.使用 :normal,你必须用 :execute 包装它才能附加 :call,但实际上你的映射没有根本不需要使用:normal:

The repeat#set() invocation must be done after the mapping invocation, not just once after the mapping definition. With :normal, you'd have to wrap this with :execute to be able to append the :call, but actually your mapping doesn't need to use :normal at all:

:nnoremap <silent> <Plug>MyWonderfulMap yyp<c-v>$r=:silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)<CR>
:nmap <Leader>h1 <Plug>MyWonderfulMap

这篇关于Vim - 如何使您自己的映射可重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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