hecal3 / vim-leader-guide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nmap vs vmap ?

ctjhoa opened this issue · comments

Hi there,
I'm try to implement a leader mapping with different action if I'm in visual mode or not.
I'm using:

nmap <silent> <leader>j=  mzgg=G`z
vmap <silent> <leader>j=  ==

If I do that, the plugin always display

mzgg=G`z

but the behaviour is as intended.
So is there a way to customize the ouput of mapping (like a special comment or something)
or is there anyway equivalent with the let g:lmap syntax ?
Thanks

Thanks for reporting that.

This was indeed not working as intended. There was a bug in the visual mode detection.
The latest commit should fix it.

Nice thanks @hecal3 ! Is there a way to customize the ouput instead of display the mapping ?
If I want to display "reindent-buffer" instead of "mzgg=G`z"

Yes, I see two possible solutions.

I'd recommend to use the following mappings:

nnoremap <silent> <SID>reindent-buffer mzgg=G`z
nmap <leader>j <SID>reindent-buffer

Then you can hide the <SID>-Prefix with the displayfunc.
See :h leaderGuide_displayfunc. The first example. Just replace <Plug> with <SID> (or add another substitute) and the example should work for this use case. You can basically run arbitrary operations on the display text, "mzgg=G`z" in your case.

If you don't want to use a <SID> or <Plug> mapping, there is also the possibility to just use a simple lookup dictionary in the display function. It's shown in the second example.

Edit: Fixed the mappings above. I accidentally messed up nmap and nnoremap.