Here is my keymap:

nmap <A-y> viW<Plug>VSurround]%a()<ESC>h"+pF(<CR>l
vmap <A-y> <Plug>VSurround]%a()<ESC>h"+pF(<CR>l

Which is a markdown link paste helper. It will make the word "Apple" to "[Apple](url in your clipboard)".

It works fine.

But when I want to undo it (change the text back to "Apple") I need press 3 times u which is unconvenient for me.

How to make it atomic (just press one time u)?

I do some search work but cant get related topic.

1 Answer 1


To have an atomique operation I would avoid 'Surround' and do:

vnoremap <A-y> "ac[<C-r>a](<C-r>+)<Esc>
nmap <A-y> viW<A-y>

It is simple but override the a buffer.

Another solution that doesn't override the a buffer is:

vnoremap <A-y> <Esc>a](<C-r>+)<Esc>gvo<Esc>i[<Esc>
nmap <A-y> viW<A-y>

It uses the visual selection v, the visual reselection gv and the cursor movement around the selection o.

  • 1
    Since you have a visual mode mapping, why not use it in the normal mode mapping as in nmap viW<A-y>?
    – romainl
    Commented Jan 1, 2023 at 15:06
  • @romainl Thanks for the hint I have updated the solution :-) Commented Jan 1, 2023 at 19:21
  • I am pretty sure that wrapping the RHS in a function (using normal, probably) and calling it from the mapping makes u work as expected.
    – D. Ben Knoble
    Commented Jan 3, 2023 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.