映射vim中的shift键 [英] mapping the shift key in vim

查看:2548
本文介绍了映射vim中的shift键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VIM中映射 Shift 键时遇到问题。我想要 Ctrl + L Ctrl + Shift + / p>

所以我有这个

 for insert mode remap< c -l> to:
为ruby插入一个哈希火箭
插入一个 - > php
为咖啡,shift键决定

函数! SmartHash(...)
let shift = a:0> 0
let ruby​​ =& ft =='ruby'
let php =& ft =='php'
let coffee =& ft =='coffee'

if php
return\->
end

如果咖啡
返回班次? \ => \ n:\ - > \\\

end

如果ruby
返回\ =>
end

return

endfunction

imap< c-l> < c-r> = SmartHash()< cr>
imap< C-S-L> < c-r> = SmartHash(1)< cr>

...但它只是触发第二个映射,无论我是否有 Shift 按键。



根据接受的答案更新



 插入模式重映射到:
为ruby $ b插入哈希火箭$ b插入一个 - >对于php和coffeescript
双击确实替代符号为php和coffescript
功能! SmartHash(...)
let alt = a:0> 0
let ruby​​ =& ft =='ruby'
let php =& ft =='php'
let coffee =& ft =='coffee'

if php || coffee
return alt? \ => \ n:\ - > \\\

end

如果ruby
返回\ =>
end

return

endfunction

imap< c-l> < c-r> = SmartHash()< cr>
imap< c-l>< c-l> < c-r> = SmartHash(1)< cr>


解决方案

由于键盘输入内部处理,这不幸的是今天是不可能的,即使在GVIM。这是一个已知的痛点,是关于vim_dev和#vim IRC频道的各种讨论的主题。



有些人(最重要的是Paul LeoNerd Evans)甚至对于支持此的终端中的控制台Vim),并且已经浮动了各种提议,cp。 http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8



但截至今天,没有补丁或志愿者尚未出现,虽然许多人已表示希望在未来的Vim 8主要版本中拥有这一点。 / p>

我通常通过使用 g 开始替换映射来解决这个问题,例如< C-l> g ,但是在插入模式下不起作用。在你的情况下,用一点额外的逻辑,你可以在同一位置第二个< C-l> 改变以前插入的 - > 到 => ,以便您通过< C-l& code>,第二个通过< C-l>< C-1>


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.

Updated based on accepted answer

" 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>.

这篇关于映射vim中的shift键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆