google / vim-maktaba

Consistent Vimscript
Apache License 2.0
591 stars 42 forks source link

Implement keymapping helpers #222

Open dbarnett opened 4 years ago

dbarnett commented 4 years ago

Implements maktaba helpers for programmatically managing vim key mappings (as in the :map command) in maktaba#keymapping# and maktaba#keymappingspec#.

Usage examples:

call maktaba#keymapping#Map(',=b', ':FormatCode<CR>', 'n')
call maktaba#keymappingspec#Spec(',=b', ':FormatCode<CR>', 'n')
    \.WithArgs(['<silent>', <buffer>']).Map()

See keymapping.vroom and :help maktaba.KeyMapping for details.

Resolves #221.

dbarnett commented 4 years ago

I'd held off on merging this PR for a while because

  1. The "full" implementation was surprisingly complex (vs. the simpler hack I originally found https://github.com/dbarnett/dotfiles/blob/8c9dc859db/.vimrc#L310) and I was hoping to find ways to reduce the scope a bit, and
  2. I'd seen a few quirks in the meantime while trying it out that I was hoping to troubleshoot further.

I'm still looking into those, but went ahead and submitted some fixes and resolved review comments while I'm looking at it.