当键已经映射到我的.vimrc中时,我如何访问键(用于它的原始函数)?
在我的例子中:我映射了,来注释当前行。但是,如果您使用f/F/t/T搜索当前行中的一个字符,,也用于继续搜索。那么,如何在,的原始函数中访问它(继续搜索)?
发布于 2016-12-22 22:55:04
如果您想保留原来的,命令,则必须将该命令映射到不同的键:
:nnoremap \\ ,或者更改遮挡命令的贴图。我知道这很困难;最终你会用完短的和容易记忆的密钥,并且必须做出权衡:-(
最好保持,密钥不会发生冲突,所以可以使用\c。如果这样已经被采用,,c也可以工作。对于原始命令,会有一个很短的延迟,因为Vim需要决定,是一个完整的命令,还是,c映射的第一个键。如果你走这条路,也许:nnoremap ,, ,会有所帮助。猛击,两次比等待超时更快。
以编程方式
尽管在交互式键入时不可行,但您始终可以通过:normal! (注意!)调用原始的、未映射的功能:
:normal! ,发布于 2016-12-23 16:57:37
下面是一组允许您执行原始的内置映射的映射。它们依赖于这样一个事实,即从:help :map-expression返回的任何内容都是字面意义上的(不需要重新映射),因此只需通过它传递任何命令的第一个键,就可以跳过覆盖它的自定义映射。
"[count]["x]<Leader><BS>{cmd}
"<Leader><BS>[count]["x]{cmd}
" Use the built-in, unmapped normal / visual /
" operator-pending mode {cmd} instead of the mapping that
" overrides the command.
"CTRL-G <BS>{cmd} Use the built-in, unmapped insert / command-line mode
" {cmd} instead of the mapping that overrides the command.
function! s:BuiltInCommand()
let l:sequence = ''
while 1
let l:key = ingo#query#get#Char()
if l:key ==# "\<Esc>"
" Abort with beep.
return l:key
elseif l:key ==# '"'
let l:sequence .= l:key
" Query the register; we won't handle the expression register here.
let l:key = ingo#query#get#Register("\<Esc>", '=')
if l:key ==# "\<Esc>"
" Abort with beep.
return l:key
endif
elseif l:key !~# '\d'
" This is the beginning of the built-in command; we're done.
let l:sequence .= l:key
return l:sequence
endif
" Keep querying for [count] numbers, registers, or the beginning of the
" command.
let l:sequence .= l:key
endwhile
endfunction
noremap <expr> <Leader><BS> <SID>BuiltInCommand()
sunmap <Leader><BS>
noremap! <expr> <C-g><BS> ingo#query#get#Char()这需要我的ingo-library plugin中的一些函数。例如,要使用原始,,请键入<Leader><BS>,。
https://stackoverflow.com/questions/41285571
复制相似问题