I'm having an issue when mapping the Shift key in VIM. I want Ctrl+L to behave differently than Ctrl+Shift+L
so I have this
" 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>
...but it's just triggering the second mapping whether I have the Shift key pressed or not.
" 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>
Due to the way that the keyboard input is handled internally, this unfortunately isn't possible today, even in GVIM. This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.
Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8
But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.
I usually work around this by starting my alternate mapping with g
, e.g. <C-l>
and g<C-l>
, but that won't work in insert mode. In your case, with a little bit of additional logic, you could make a second <C-l>
at the same position change the previously inserted ->
to =>
, so that you get the first alternative via <C-l>
, and the second via <C-l><C-l>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With