[英]Vim's <Plug> based mappings don't work with :normal command
Say, I have the following 说,我有以下内容
:nm <Plug>Ls :ls<CR>
:nm <Leader>L <Plug>Ls
When I do a ,L ( ,
being the leader), I do get the output of :ls
command. 当我做了,L( ,
是领导者),我得到的输出:ls
命令。 I also get the output when I do :normal ,L
, but I don't when doing the following 当我这样做时,我也得到了输出:normal ,L
,但是在执行以下操作时我没有
:normal <Leader>L
:normal <Plug>Ls
I can understand why the first isn't working, I suppose I have to do something like execute 'normal ' . mapleader . 'L'
我能理解为什么第一个不起作用,我想我必须做一些像execute 'normal ' . mapleader . 'L'
事情execute 'normal ' . mapleader . 'L'
execute 'normal ' . mapleader . 'L'
execute 'normal ' . mapleader . 'L'
. execute 'normal ' . mapleader . 'L'
。 What I can't figure out is the second one. 我无法弄清楚的是第二个。 It doesn't give me any error, It just doesn't do anything, which is what driving me crazy. 它没有给我任何错误,它只是没有做任何事情,这是让我发疯的原因。 I couldn't find anything on this in the docs either. 我在文档中找不到任何相关内容。
What I want to do is run whatever is mapped to <Plug>Ls
, from the command mode (in a function actually). 我想要做的是从命令模式(实际上在一个函数中)运行映射到<Plug>Ls
任何内容。 Any dark hacks needed for this? 这需要黑暗的黑客吗?
They do work with normal, you just are not supplying it <Plug>
, you supply <
, P
, l
, u
, g
, >
. 它们可以正常工作,你只是不提供<Plug>
,你提供<
, P
, l
, u
, g
, >
。 Correct syntax is 正确的语法是
:execute "normal \<Plug>Ls"
Same applies to feedkeys()
: call feedkeys("\\<Plug>Ls")
, not call feedkeys("<Plug>Ls")
. 同样适用于feedkeys()
: call feedkeys("\\<Plug>Ls")
,而不是call feedkeys("<Plug>Ls")
。
Also note that execute "normal ".mapleader."L"
should not really be ever used as if mapleader
changes after you execute :nm <Leader>L <Plug>Ls
, then this :execute …
will try to call nonexistent mapping ( mapleader
changes do not affect already created mappings). 另外请注意, execute "normal ".mapleader."L"
实在不应该被使用过,就好像mapleader
改变你执行后:nm <Leader>L <Plug>Ls
,那么这个:execute …
将尝试调用不存在的映射( mapleader
更改不会影响已创建的映射)。 And you there are no ways to know whether mapleader
has changed. 而且你无法知道mapleader
是否已经改变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.