I use the following mapping to send code to a REPL using vim-slime and tmux:

nmap <buffer> <S-CR> <Plug>SlimeLineSend

How can I perform an action after I invoque this mapping?. For example, I would like to move down one line (j) after the <Plug>SlimeLineSend is executed. This does not work:

nmap <buffer> <S-CR> <Plug>SlimeLineSend j

This almost works for me:

nmap <buffer> <S-CR> <Plug>SlimeLineSendj

The reason it actually doesn't work is that my terminal Vim actually doesn't recognize the <S-CR> sequence as different from a simple <CR>, so whenever I press <S-CR> Vim just moves to the next line and doesn't really trigger the mapping... If I do the same using a different trigger, it works fine:

nmap <buffer> <LocalLeader>s <Plug>SlimeLineSendj

Whenever expanding a mapping, Vim will look for the longest sequence of characters that matches a mapping. In this case, this will be <Plug>SlimeLineSend, which will trigger the action. The j is still on the buffer, so Vim will use this command as a motion to go down one line.

(Many plug-ins create their <Plug> mappings with a set of parens around the "command" part, so that it's clear where it ends. Also, that allows them to create commands that are prefixes of other commands. For example, emmet.vim has <Plug>(emmet-toggle-comment), Command-T has <Plug>(CommandT), etc.)

  • 1
    Yes, this works! Hmm, I thought I tried your approach without success. Apparently I was doing something different. This is cleaner than my answer. Thanks. – mroavi Aug 19 '20 at 23:18

I came up with a solution based on this answer: https://stackoverflow.com/a/18547013/1706778

nmap <buffer> <S-CR> :execute "normal \<Plug>SlimeLineSend"<CR>j
  • 3
    In that case, you don't nmap and nnoremap suffices – D. Ben Knoble Aug 19 '20 at 23:20
  • 1
    @Ben Yes! In fact this is one of the advantages of this approach. That you can use nnoremap in this case and the parts outside the <Plug> are never recursively expanded. If you use nnoremap here and you map j to go up, this mapping will still go down. But with the one I suggested, if you remap j, you'll get the remapped j behavior there... – filbranden Aug 19 '20 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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