Vim - 带有可选寄存器前缀的映射 [英] Vim - mapping with an optional register prefix

查看:29
本文介绍了Vim - 带有可选寄存器前缀的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我发现在 Vim 中对我来说一个常见的任务是 PUT 到行首或行尾.所以我的映射可能是:

So I've discovered that a common task for me in Vim is to PUT either to the start of the line or the end of the line. So my mapping could be:

nmap <Leader>p $p
nmap <Leader>P 0P

然而,我真正想做的是在放置之前可选地包含一个寄存器.

However, what I'd really like to do is optionally include a register before putting.

例如 "a,P 会将寄存器 a 放在行首.

So for example "a,P would put from register a to the beginning of the line.

有没有办法用映射来做到这一点?

Is there a way do this with a mapping?

推荐答案

你可以在一行中使用 映射来做到这一点:

You can do this using <expr> mapping in one line:

nnoremap <expr> \p '$"'.v:register.v:count1.'p'
nnoremap <expr> \P '0"'.v:register.v:count1.'P'

这篇关于Vim - 带有可选寄存器前缀的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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