vim의 교체 모드에서 키를 다시 매핑

vim의 교체 모드에서 키를 다시 매핑

세미콜론과 콜론 키를 바꾸려고 합니다.

나는 이 기능을 사용한다

func! FUNC_Remap(lhs, rhs)
    " Function which remaps keys in all modes
    "
    ":echom 'inoremap '.a:lhs.' '.a:rhs
    "http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_1)
    "  CHAR MODE    ~
    " <Space>   Normal, Visual, Select and Operator-pending
    "n  Normal
    "v  Visual and Select
    "s  Select
    "x  Visual
    "o  Operator-pending
    "!  Insert and Command-line
    "i  Insert
    "l  ":lmap" mappings for Insert, Command-line and Lang-Arg
    "c  Command-line
    "--------------
    " Normal Mode
    :exec 'noremap '.a:lhs.' '.a:rhs
    " Visual and Select Mode
    :exec 'vnoremap '.a:lhs.' '.a:rhs
    " Display select mode map
    :exec 'snoremap '.a:lhs.' '.a:rhs
    " Display visual mode maps
    :exec 'xnoremap '.a:lhs.' '.a:rhs
    " Operator Pending Mode
    :exec 'onoremap '.a:lhs.' '.a:rhs
    " Insert and Replace Mode
    :exec 'inoremap '.a:lhs.' '.a:rhs
    " Language Mode
    :exec 'lnoremap '.a:lhs.' '.a:rhs
    " Command Line Mode
    :exec 'cnoremap '.a:lhs.' '.a:rhs
endfu
command! -nargs=* CMDREMAP call FUNC_Remap(<f-args>)

func! FUNC_Swap(lhs, rhs)
    :call FUNC_Remap(a:lhs, a:rhs)
    :call FUNC_Remap(a:rhs, a:lhs)
endfu
command! -nargs=* CMDSWAP call FUNC_Swap(<f-args>)    

:CMDSWAP : ;

모든 인스턴스에서 작동하지만 교체 모드에서는 작동합니다.

문서를 읽으면 inoremap이 교체 모드를 다루어야 한다고 나와 있는데 r을 입력하면; 일반 모드에서는 현재 문자를 매핑되어야 하는 콜론 대신 세미콜론으로 바꿉니다. 매핑이 다른 모든 곳에서 작동하면 매우 짜증납니다.

교체 모드에서 작동하도록 키를 다시 매핑하려면 어떻게 해야 합니까?

답변1

교체 모드기존 문자를 입력된 텍스트로 바꾸는 삽입 모드의 변형입니다. 단일 문자 교체는 다음과 r같습니다.교체 모드, 특별한 모드도 아닙니다. 따라서 :map명령은 거기에 적용되지 않습니다. 좋은 비결은 전체 명령 + 문자 조합을 다시 매핑하는 것입니다.

nnoremap r; r:
nnoremap r: r;

또는 다음을 사용할 수 있습니다 :lmap. CP. :help r:

      |:lmap| mappings apply to {char}.  The CTRL-^ command
      in Insert mode can be used to switch this on/off

관련 정보