我刚刚开始学习 Vim。我在 gnome-terminal 中使用 Vim(在 Ubuntu 14.04 上)。我想将 kj 键映射到 vimrc 文件中的 Esc。我在 vimrc 文件 (~/.vimrc) 中添加了以下两行:
inoremap kj <Esc>
cnoremap kj <Esc>
问题 1: 我获取了 vimrc 文件(甚至重新启动了终端),但是当我在插入模式下快速键入 kj 时,它只键入这两个字母 kj 而不会进入正常模式。难道我做错了什么?将 Esc 键映射到其他键的正确方法是什么?
问题 2: 我应该如何编辑 vimrc 以将大写键映射到 Esc?
在 Vim 中,
:echo $COLORTERM
显示“gnome-terminal”
作为引用,这是我完整的 vimrc 文件(无注释):
set t_Co=256
colorscheme wombat256mod
syntax on
set hlsearch
set incsearch
set number
set autoindent
set ts=4
set ignorecase
set title
set scrolloff=5
" Map <ESC> key to kj
inoremap kj <Esc>
cnoremap kj <Esc>
set paste
set cursorline
最佳答案
当粘贴模式处于事件状态时,插入模式键盘映射将不起作用,并且默认情况下它处于事件状态:
set paste
您可能最好删除该行,以便粘贴模式不处于事件状态,并添加一种简单的方法在您需要时将其打开。我用这个:
set pastetoggle=,p
粘贴模式默认为关闭,我可以使用 ,p
轻松切换它
来自 :help '粘贴
:
When the 'paste' option is switched on (also when it was already on):
- mapping in Insert mode and Command-line mode is disabled
- abbreviations are disabled
- 'textwidth' is set to 0
- 'wrapmargin' is set to 0
- 'autoindent' is reset
- 'smartindent' is reset
- 'softtabstop' is set to 0
- 'revins' is reset
- 'ruler' is reset
- 'showmatch' is reset
- 'formatoptions' is used like it is empty
These options keep their value, but their effect is disabled:
- 'lisp'
- 'indentexpr'
- 'cindent'
关于ubuntu - Vim新手: Mapping kj key to <Esc> not working in gnome terminal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33970359/