Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<Plug> functions or something similar to use to configure mappings #222

Closed
farzadmf opened this issue Jan 5, 2023 · 14 comments · Fixed by folke/which-key.nvim#389
Closed

Comments

@farzadmf
Copy link

farzadmf commented Jan 5, 2023

Describe the issue:

Hi, this is more of a question rather than a "real" issue. I'm a BIG fan of this plugin, and I use it almost every minute.

I'm in the process of doing an overhaul of my config, and, looking at the mapping options in the Wiki, I just realized that the plugin has WAY MORE potential than what I'm currently using.

However, because I'm using which-key and smiliar things, I've set my timeoutlen to 300, which makes it very hard to use this plugin's leader in a key combination.

I was wondering if there are <Plug> functions (or another method) similar to other plugins that I can directly map myself.

PS: I didn't fill all the template fields for an issue. Please let me know if you want me to do that

PS 2: I know I can directly assign g:VM_maps[<the-thing-I-want>] to a key without the leader, but going through the mappings in the Wiki (and considering the large number of other plugins I have), I'm pretty sure I'll get a conflict after setting a few of these.


Steps to reproduce


  • Operating System:
  • Vim Version:
  • commit SHA/branch:
@mg979
Copy link
Owner

mg979 commented Jan 5, 2023

You can set

let g:VM_default_mappings = 0

then map the plugs yourself (but <c-n> is always mapped, you should change it with VM_maps).

The plugs should be listed in :help vm-mappings, or just look for them here.

For buffer mappings currently it isn't possible though. I'll probably add an option to skip all mappings, letting you assign them from the ground up, including buffer mappings. But I make no promise on this because it is pretty complicated, given the number of mappings/plugs that must be applied.

@farzadmf
Copy link
Author

farzadmf commented Jan 5, 2023

Thank you @mg979 for your reply

The plugs should be listed in :help vm-mappings

Not exactly sure what I should be looking for

So, to test I did this:

nnoremap <M-h> <Plug>(VM-Add-Cursor-Down)<CR>

And when I press alt + h in the middle of the current line, a cursor is added in the next line but the cursor moves to the beginning of the line after that (2 lines after current line):

So, If I keep repeating alt + h, 2 cursors are added to my current line and one after that, and the rest at the beginning of each line; something like this:
image

Is there something I'm missing?

@mg979
Copy link
Owner

mg979 commented Jan 5, 2023

It should be

nmap <M-h> <Plug>(VM-Add-Cursor-Down)

without <cr>, and use nmap.

@farzadmf
Copy link
Author

farzadmf commented Jan 5, 2023

Great, thanks @mg979 , gonna close this then

Just one question: where are these "functions" mentioned in :h vm-mappings? Is there a way to see them locally without needing to come to GitHub to check?

@farzadmf farzadmf closed this as completed Jan 5, 2023
@mg979
Copy link
Owner

mg979 commented Jan 5, 2023

:help vm-functions

@farzadmf
Copy link
Author

farzadmf commented Jan 5, 2023

:help vm-functions

Hmm, I don't seem to have the help topic 🤔

I have :h vim-faq-functions, but :h vm-functions gives Sorry, no help for vm-functions

@mg979
Copy link
Owner

mg979 commented Jan 5, 2023

There is, maybe you have to update the help tags.

:helptags ALL

@farzadmf
Copy link
Author

farzadmf commented Jan 7, 2023

Hey @mg979 , question for you:

I'm trying to integrate the plugs with folke/which-key, and I see issues.

At first, I thought it's because which-key adds a <cr> at the end of my mapping, but I think the reason is that when a "popup window" appears, I think VM exits out of its mode (I may very well be super wrong)

Do you know if I can basically integrate this mapping into which-key (or other plugins that "open a popup window" to allow me select the command I want to run)?

Thank you in advance

@mg979
Copy link
Owner

mg979 commented Jan 7, 2023

when a "popup window" appears, I think VM exits out of its mode

When leaving current buffer, VM exits, yes.

https://github.com/folke/which-key.nvim/blob/b7e0b1f16c20bc1ea0515851bc5740d1c1f18444/lua/which-key/view.lua#L140

I see which-key has already some attempt at compatibility, but it's not robust. Maybe you have changed the mapping to reselect regions?

@mg979
Copy link
Owner

mg979 commented Jan 7, 2023

The issue you had should be fixed (update which-key plugin), reopen if it isn't.

@mg979 mg979 closed this as completed Jan 7, 2023
@farzadmf
Copy link
Author

farzadmf commented Jan 7, 2023

Maybe you have changed the mapping to reselect regions?

I don't think I've changed it, but not sure which mapping that is 🤔

The issue you had should be fixed

It indeed seems to be fixed 🎉


So, @mg979 , there are some other plugins similar to which-key (such as key-menu). Does this change mean that the upstream code has to change to adopt visual multi, or can I configure something on my side only (maybe the reselect regions thing you mentioned)?

@farzadmf
Copy link
Author

Hey @mg979 , didn't hear back from you, so I have another issue for you 🙂

I'm using hydra.nvim to do my VM "tasks", and I can successfully do VM-Add-Cursor-Down and VM-Add-Cursor-Up.

However, I tried to add VM-Add-Cursor-At-Pos, for example, and I see this error:

Error detected while processing function vm#commands#add_cursor_at_word[2]..<SNR>76_init[11]..function vm#commands#add_cursor_at_word[2]..<SNR>76_init:
line   11:
E605: Exception not caught: VM cannot start, unhandled exception.

Or, for VM-Add-Cursor-At-Word I get this error:

Error detected while processing function vm#commands#add_cursor_at_word[2]..<SNR>76_init:
line   12:
E121: Undefined variable: s:F

I'm calling them all the same:

<Plug>(VM-Add-Cursor-Down)    <-- this works
<Plug>(VM-Add-Cursor-Up)      <-- this works
<Plug>(VM-Add-Cursor-At-Pos)  <-- error!
<Plug>(VM-Add-Cursor-At-Word) <-- error!

Do you think there's something I need to do to avoid those errors?

@mg979
Copy link
Owner

mg979 commented Jan 13, 2023

The plugs work with :normal, so I have no idea.

@farzadmf
Copy link
Author

Thank @mg979 , it seems like that I couldn't make things work by using Hydra or which-key. I think I'll end up using the VM leader and see if things work as I want them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants