2

Is it possible so that each of the different visual modes have different mappings? For example:

visual-block-noremap     A      BB
visual-line-noremap      A      CC
visual-normal-noremap    A      DD

If so, what are the various mappings that can be used? Normally, I've used vnoremap for everything.

2

Vim has no built-in way to differ mappings for Visual sub-modes, and I can't think of any good use case for this either, but it's certainly not too hard to do. For instance,

xnoremap <expr>A VisualMapping('BB', 'CC', 'DD')

function! VisualMapping(char, line, block) abort
    if mode() ==# 'v'
        return a:char
    elseif mode() ==# 'V'
        return a:line
    elseif mode() ==# "\<C-V>"
        return a:block
    endif
endfunction
2
  • visualmode() returns the last visual mode; you want the current mode (i.e. mode()).
    – user938271
    Jun 20 '20 at 9:40
  • 1
    @user938271 Ah, yeah... I didn't check it at all. When you do it with <expr> you need mode(), but when it's without it you need visualmode() (as you've just left it).
    – Matt
    Jun 20 '20 at 10:12

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.