Shift在 VIM 中映射密钥时遇到问题。我希望Ctrl+L的行为与Ctrl+ Shift+不同L
所以我有这个
" for insert mode remap <c-l> to:
" Insert a hash rocket for ruby
" Insert a -> for php
" for coffee the shift key decides
function! SmartHash(...)
let shift = a:0 > 0
let ruby = &ft == 'ruby'
let php = &ft == 'php'
let coffee = &ft == 'coffee'
if php
return "\->"
end
if coffee
return shift ? "\ =>\n" : "\ ->\n"
end
if ruby
return "\ => "
end
return ""
endfunction
imap <c-l> <c-r>=SmartHash()<cr>
imap <C-S-L> <c-r>=SmartHash(1)<cr>
...但是无论我是否Shift按下了键,它都只是触发了第二个映射。
根据接受的答案更新
" for insert mode remap <c-l> to:
" Insert a hash rocket for ruby
" Insert a -> for php and coffeescript
" double tapping does alternate symbol for php and coffescript
function! SmartHash(...)
let alt = a:0 > 0
let ruby = &ft == 'ruby'
let php = &ft == 'php'
let coffee = &ft == 'coffee'
if php || coffee
return alt ? "\ =>\n" : "\ ->\n"
end
if ruby
return "\ => "
end
return ""
endfunction
imap <c-l> <c-r>=SmartHash()<cr>
imap <c-l><c-l> <c-r>=SmartHash(1)<cr>