Vim:操作员待定模式重新映射不起作用

Vim:操作员待定模式重新映射不起作用

我正在尝试构建一个可以与 Dvorak 简化布局一起使用的 vimscript。即,假设插入计算机的键盘上的按键采用 Dovark 简化布局布局(并且系统的键盘设置也相应设置),我想编写一个 vimscript,使 vim 仅在插入模式下使用 Dvorak 布局:在所有其他模式下,键盘布局将为 QWERTY。

以下是我所拥有的:

"Keys between the 0 and the backspace
noremap [ -
noremap { _
noremap ] =
noremap } +

"Keys from the tab till the end of the row
noremap ' q
noremap " Q
noremap , w
noremap < W
noremap . e
noremap > E
noremap p r
noremap P R
noremap y t
noremap Y T
noremap f y
noremap F Y
noremap g u
noremap G U
noremap c i
noremap C I
noremap r o
noremap R O
noremap l p
noremap L P
noremap / [
noremap ? {
noremap = ]
noremap + }

"Home row keys
noremap o s
noremap O S
noremap e d
noremap E D
noremap u f
noremap U F
noremap i g
noremap I G
noremap d h
noremap D H
noremap h j
noremap H J
noremap t k
noremap T K
noremap n l
noremap N L
noremap s ;
noremap S :
noremap - ,
noremap _ "

"Keys for the row below the home row
noremap ; z
noremap : Z
noremap q x
noremap Q X
noremap j c
noremap J C
noremap k v
noremap K V
noremap x b
noremap X B
noremap b n
noremap B N
noremap w ,
noremap W <
noremap v .
noremap v >
noremap z /
noremap Z ?

"Same as above but now for the console

"Keys between the 0 and the backspace
cnoremap [ -
cnoremap { _
cnoremap ] =
cnoremap } +

"Keys from the tab till the end of the row
cnoremap ' q
cnoremap " Q
cnoremap , w
cnoremap < W
cnoremap . e
cnoremap > E
cnoremap p r
cnoremap P R
cnoremap y t
cnoremap Y T
cnoremap f y
cnoremap F Y
cnoremap g u
cnoremap G U
cnoremap c i
cnoremap C I
cnoremap r o
cnoremap R O
cnoremap l p
cnoremap L P
cnoremap / [
cnoremap ? {
cnoremap = ]
cnoremap + }

"Home row keys
cnoremap o s
cnoremap O S
cnoremap e d
cnoremap E D
cnoremap u f
cnoremap U F
cnoremap i g
cnoremap I G
cnoremap d h
cnoremap D H
cnoremap h j
cnoremap H J
cnoremap t k
cnoremap T K
cnoremap n l
cnoremap N L
cnoremap s ;
cnoremap S :
cnoremap - ,
cnoremap _ "

"Keys for the row below the home row
cnoremap ; z
cnoremap : Z
cnoremap q x
cnoremap Q X
cnoremap j c
cnoremap J C
cnoremap k v
cnoremap K V
cnoremap x b
cnoremap X B
cnoremap b n
cnoremap B N
cnoremap w ,
cnoremap W <
cnoremap v .
cnoremap v >
cnoremap z /
cnoremap Z ?

但出于某种原因,按下物理键盘上的“ii”键(应该跳转到文档开头)(因为在普通模式和 Operator-Pending 模式下,“i”键都映射到“g”)时,vim 进入了插入模式。然而,按下物理键盘上的“ig”键确实会跳转到文档开头。

无论是在 Linux 还是 Windows 上,该问题仍然存在。

为什么操作待定模式映射不起作用?Vim 帮助说“noremap”重新映射除 Insert、Console、Terminal-Job 和 Lang-Arg 之外的所有模式。

答案1

gg不是正常模式g+ 运动g;它本身就是一个完整的正常模式映射,并且必须像这样映射:

nnoremap ii gg

但是,我认为你的整个方法都是有缺陷的,并且会导致问题。至少,Dvorak 布局通常以不同的方式实现,:help 'keymap'。 看使用带有 Dvorak 键盘布局的 Vim,然后退房$VIMRUNTIME/keymap/dvorak.vim

相关内容