Vim <Plug> based mappings do not work: normal command

Say I have the following

:nm <Plug>Ls :ls<CR> :nm <Leader>L <Plug>Ls 

When I do L ( , ), I get the output of the command :ls . I also get output when I do :normal ,L , but I do not do the following

 :normal <Leader>L :normal <Plug>Ls 

I can understand why the first does not work, I suppose I need to do something like execute 'normal ' . mapleader . 'L' execute 'normal ' . mapleader . 'L' execute 'normal ' . mapleader . 'L' . What I cannot understand is the second. It does not give me any mistake, it just does nothing, which drives me crazy. I could not find anything in the documents either.

What I want to do is run everything that is displayed on <Plug>Ls from command mode (actually in a function). Any dark hacks needed for this?

+7
source share
1 answer

They work fine, you just don't supply it with <Plug> , you supply with < , P , l , u , g , > . The correct syntax

 :execute "normal \<Plug>Ls" 

The same applies to feedkeys() : call feedkeys("\<Plug>Ls") , not call feedkeys("<Plug>Ls") .

Also note that execute "normal ".mapleader."L" should never be used as if mapleader changed after execution :nm <Leader>L <Plug>Ls , then this :execute … will try to invoke a nonexistent map ( mapleader changes do not affect already created mappings). And you cannot find out if mapleader has changed.

+10
source

All Articles