我知道你在 Windows 下有 Zeal ,你在 Mac OS X 用 Dash,但是你想在服务器上或者任意命令行环境下查看 C/C++ 语言手册么?偶尔看别人代码里调用到一个冷僻的 libc 函数(比如 strpbrk这种),网页搜索太慢,运行 zeal/dash 麻烦,想在命令行直接查看帮助怎么办?
上面在 SecureCRT / XShell 中设置了将 alt 键作为发送 +ESC x 的 meta 键后,你会发现,终端软件中固有的一些 ALT 组合键全部失效了,比如原来在终端中 ALT_1 到 ALT_9 可以切换终端的 TAB,ALT_B 可以打开链接管理器,这下都全部用不了了,这是件比较坑爹的事情,能不能保留有限的几个 ALT 组合键给终端软件使用,剩下的全部当作 meta 键呢?答案是可以的,先取消终端里 ALT 当作 meta 键的设置,恢复成默认状态,然后打开终端软件 keymap 设置窗口,将你不需要保留的 ALT 组合键全部设置成发送 +ESC x 字符串。
那么一个个设置可能有些麻烦,对于 SecureCRT 的话,我生成了一个配置文件:
A VK_A "\033a"
A VK_D "\033d"
A VK_E "\033e"
A VK_G "\033g"
A VK_H "\033h"
....
AS VK_A "\033A"
AS VK_B "\033B"
AS VK_C "\033C"
AS VK_D "\033D"
前面在终端软件里配置好 ALT键,但是 Vim 的话,由于历史原因,需要在你的 vimrc 里加一段键盘码配置:
function! Terminal_MetaMode(mode)
set ttimeout
if $TMUX != ''
set ttimeoutlen=30
elseif &ttimeoutlen > 80 || &ttimeoutlen <= 0
set ttimeoutlen=80
endif
if has('nvim') || has('gui_running')
return
endif
function! s:metacode(mode, key)
if a:mode == 0
exec "set <M-".a:key.">=\e".a:key
else
exec "set <M-".a:key.">=\e]{0}".a:key."~"
endif
endfunc
for i in range(10)
call s:metacode(a:mode, nr2char(char2nr('0') + i))
endfor
for i in range(26)
call s:metacode(a:mode, nr2char(char2nr('a') + i))
call s:metacode(a:mode, nr2char(char2nr('A') + i))
endfor
if a:mode != 0
for c in [',', '.', '/', ';', '[', ']', '{', '}']
call s:metacode(a:mode, c)
endfor
for c in ['?', ':', '-', '_']
call s:metacode(a:mode, c)
endfor
else
for c in [',', '.', '/', ';', '{', '}']
call s:metacode(a:mode, c)
endfor
for c in ['?', ':', '-', '_']
call s:metacode(a:mode, c)
endfor
endif
endfunc
call Terminal_MetaMode(0)
然后你就可以正确在 Vim 映射 ALT 键了,具体原理见 :help set-termcap 以及: