tes*_*ter 16 vim keyboard-shortcuts
在VIM,我想缩短:tabnew
到:tn
,:tabp
到:th
,:tabn
到:tl
我的地方.vimrc
.知道如何重新映射这样的命令吗?
Sam*_*uby 24
使用cabbrev:
ca tn tabnew
ca th tabp
ca tl tabn
Run Code Online (Sandbox Code Playgroud)
您可以将以下代码添加到〜/ .vimrc文件中,并轻松浏览选项卡.
nnoremap th :tabfirst<CR>
nnoremap tj :tabnext<CR>
nnoremap tk :tabprev<CR>
nnoremap tl :tablast<CR>
nnoremap tt :tabedit<Space>
nnoremap tn :tabnext<Space>
nnoremap tm :tabm<Space>
nnoremap td :tabclose<CR>
Run Code Online (Sandbox Code Playgroud)
Daniel Kullmann指出目前接受的答案很危险.
如果您使用ca tn tabnew
,只要您键入字符串th
,它就会意外扩展.
例如,:!ls /tmp/tn/
将扩展为:!ls /tmp/tabnew/
本答案中列出的方法不会遇到同样的问题.使用它看起来像这样:
cnoreabbrev <expr> tn getcmdtype() == ":" && getcmdline() == 'tn' ? 'tabnew' : 'tn'
cnoreabbrev <expr> th getcmdtype() == ":" && getcmdline() == 'th' ? 'tabp' : 'th'
cnoreabbrev <expr> tl getcmdtype() == ":" && getcmdline() == 'tl' ? 'tabn' : 'tl'
cnoreabbrev <expr> te getcmdtype() == ":" && getcmdline() == 'te' ? 'tabedit' : 'te'
Run Code Online (Sandbox Code Playgroud)
这些自定义确保仅在命令和其他任何地方进行扩展.
归档时间: |
|
查看次数: |
9882 次 |
最近记录: |