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

Ability to change what happens when pasting with Cmd+v the editor while still being able to use Cmd+v to paste in dialogs #1505

Open
adamnovak opened this issue Oct 21, 2024 · 7 comments
Labels
Input Issues related to keyboard or other types of input

Comments

@adamnovak
Copy link

adamnovak commented Oct 21, 2024

Is your feature request about something that is currently impossible or hard to do? Please describe the problem.

I'm trying to customize paste behavior in MacVim in insert mode, to add come <C-g>u sequences to create undo points before and after the pasted text.

I can do that with an inoremap <D-v>. But in order for <D-v> to make it to the Vim input processing, it can't be bound in the MacVim menu system to the paste: action. So the folks at SuperUser suggest:

macmenu Edit.Paste key=<nop>
noremap <D-v> "*P
cnoremap <D-v> <C-r><C-o>*
inoremap <D-v> <C-g>u<C-r><C-o>*

But if you do that, then paste doesn't work in dialogs and other non-Vim UI elements insider MacVim, such as the graphical find dialog. As noted in the MacVim help on customizing the menu:

(E.g. the menu item "Edit.Paste" must be bound to the action "paste:" otherwise pasting won't work in dialogs since that is the action that instructs them to paste something.)

And I can't find any documentation on how to either change what happens when a paste: action is received by the Vim layer, or to set what happens when a <D-v> is sent to the GUI layer when it's not bound to a menu option.

So I'm not able to achieve the configuration where pressing Command+v creates undo points around the pasted text in Vim's insert mode, but also still works on text boxes in the GUI.

Describe the solution you'd like

My ideal approach would be to have paste: reach the Vim core exactly as if <D-v> were being typed, so that remapping <D-v> with inoremap would Just Work without having to unbind it from the menu item.

Describe alternatives you've considered
Other approaches would be:

  • Providing a command to control what MacVim actions like paste: do when they reach the Vim level.
  • Providing an option on the macmenu command to set key sequences to be issued in Vim before/after the action is processed.
  • Providing a mode-specific map-like command to map keys in the "mode" of having a dialog box selected, so that you could <something>noremap <D-v> to :macaction paste: and have that work in the dialogs. This might be totally impossible since then Vim internals would have to process all the keypresses in the dialogs.
  • Documenting some already-existing way to customize what the paste: action does by overwriting/replacing some VimScript function it already invokes.

Additional context
I only barely know enough about Vim input processing to articulate what I want to achieve, so it's possible I'm missing something obvious about how pasting works in Vim.

@ychin
Copy link
Member

ychin commented Oct 21, 2024

Yeah I have been unsatisfied with how this is handled right now. The current way of associating a key with the menu is a very "Apple-like" way of handling shortcut keys, but at the same time makes it hard to configure with Vim key bindings. It's been on my list of to-fixes but I haven't quite got around to it.

Documenting some already-existing way to customize what the paste: action does by overwriting/replacing some VimScript function it already invokes.

Yes, this is definitely needed.

Providing an option on the macmenu command to set key sequences to be issued in Vim before/after the action is processed.

This is currently roughly how I plan to attack the issue, but that may change. There are some other considerations with improving the input (e.g. meta keys, modifyOtherKeys support) so I'm trying to think about it cohesively.

But the answer is for now, yeah it's a little annoying for sure.

@ychin ychin added the Input Issues related to keyboard or other types of input label Oct 21, 2024
@adamnovak
Copy link
Author

Is there some already-existing way to hook the paste function that could be documented? If so, that would be a very useful workaround for me.

@ychin
Copy link
Member

ychin commented Oct 21, 2024

Is there some already-existing way to hook the paste function that could be documented? If so, that would be a very useful workaround for me.

No, there isn't. What you need to do is remove the paste menu item using aunmenu / tlunmenu and then manually remap <D-V> to paste yourself. It's hacky but that's the way to do it right now.

@adamnovak
Copy link
Author

OK, I tried:

aunmenu Edit.Paste
tlunmenu Edit.Paste
noremap <D-v> "*P
cnoremap <D-v> <C-r><C-o>*
inoremap <D-v> <C-g>u<C-r><C-o>*<C-g>u

And that removes Paste from the Edit menu entirely and works to free up <D-v> for my bindings. But the items don't return to the menus when I change focus to a dialog box, I think because the Vim core is still in one of the modes covered by the unmenu commands, and <D-v> in the dialogs doesn't work without the menu option.

@ychin
Copy link
Member

ychin commented Oct 22, 2024

But the items don't return to the menus when I change focus to a dialog box,

Wait, what dialog boxes?

@adamnovak
Copy link
Author

Under Edit -> Find -> Find... there's a standard-ish MacOS find and replace dialog. Here's a screenshot:
Screenshot 2024-10-23 at 12 20 13

I end up with it because I mash Command + F when I want to find things sometimes, instead of remembering to do Escape and then slash.

In those text fields, I might want to paste something, and if I do that I want to do Command + F and then Command + V right after it. But if I unbind Command + V from the menus, I can't paste in the text fields in the dialog.

Maybe I just also need to unbind Command + F from the menus so I never see the dialog. I think I already wrote bindings for it to do go to normal mode and do slash, and then never investigated why they didn't work.

@ychin
Copy link
Member

ychin commented Oct 23, 2024

Ah right yeah. But yes this is why this method is kind of a hack. I personally recommend mapping another key for this purpose for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Input Issues related to keyboard or other types of input
Projects
None yet
Development

No branches or pull requests

2 participants