我知道您可以使用 imap
将自定义键映射添加到 vim在 .vimrc
文件。我的问题是,如果要创建额外的自定义运算符、 Action 、命令并将它们映射到键,那么添加它们的最佳方法是什么,以免它们与现有绑定(bind)冲突?
打个比方,在 emacs 中,通过 C-c 序列添加了很多自定义键命令。更专业地说,vim 中是否有允许用户自定义的未绑定(bind)键?换句话说,是否有可供用户使用的免费 key 空间?
最佳答案
:imap
Enter 将显示您的插入模式映射列表。
My question is, if one is to create additional custom operators, motions, commands and map them to keys, what is the best way to add them in so they don't conflict with existing bindings?
在我看来,最好的方法是创建自定义命令,它们以大写字母开头,原生命令以小写字母开头。
此外,您可以使用
<leader>
我用,有些用\。例如
:let mapleader = ","
然后,您可以使用领导者将其与其他键组合,例如 ,p 调用命令, native 或自定义,见下文:
:map <leader>p :MyCustomCommand<CR>
自定义 Action 示例。删除光标后的第三个单词。
nnoremap <leader>x :normal 2wdw<CR>
可以使用几个命令新建 , 删除 和 列出映射 ,这里是工作模式列表,来自
:help map-overview
Normal Visual+Select Operator-pending ~
:map :noremap :unmap :mapclear yes yes yes
:nmap :nnoremap :nunmap :nmapclear yes - -
:vmap :vnoremap :vunmap :vmapclear - yes -
:omap :onoremap :ounmap :omapclear - - yes
更多信息
:help map
这是一个示例函数,转换为 自定义命令
function! MoveLastLines(f)
exe '$-9,$w ' . a:f "write last ten lines to the passed filename
$-9,$d "delete last ten lines
endfunction
command! -nargs=1 -range MoveTo :call MoveLastLines(<f-args>)
现在,下面的两行是等价的
:call MoveLastLines('newFile.txt')
:MoveTo newFile.txt
关于vim - 在 vim/vi 中添加自定义键映射的最佳方法是什么? (是否存在用于自定义的未绑定(bind)键空间?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7784993/