preservim / vim-pencil

Rethinking Vim as a tool for writing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cleanup key remapping technique

alerque opened this issue · comments

The merge of #50 accomplished something positive (allowing people with rebound motion keys to keep using their preferred key rather than the hard coded defaults) but it also introduced a regression. In fixing the regression (see #82) I observed there are several more potential problems lurking in this method.

First, Mapkey() should be refactored completely so it queries the map for a single binding rather than iterating though the entire map parsing for bindings itself.

Second, we're completely inconsistent about what keys we account for possibly having been user remapped and which we don't. I think the entire things should be fixed so that all keys respect what users may have mapped them to and Pencil's behavior gets added to their preferred mappings with no hard coded keys at all.

Third, their doesn't seem to be a reliable way to turn off all the Pencil modified bindings at once. Most of them get reverted, but not quite all. And now that we're looking an what user mappings were, we need to revert to those not just revert to hard coded defaults!

I'm opening this as an issue because I won't be able to get to this soon (traveling for a couple weeks) and don't want to loose track of things I noticed needed attention.

Possibly related: #34.

I have a suggestion. Instead of detection, what about using <Plug> bindings? With these, you can make movement commands a user binds their keys to, and pencil manages the meaning of these commands to suit the wrap mode.

On startup you'd make bindings like:

nnoremap <Plug>Pencilkeys_down j
nnoremap <Plug>Pencilkeys_AltDown gj
...

The user would bind to these plug mappings in their rc file.

And when you initialize pencil mode, you'd change what the plug mappings do for the buffer:

nnoremap <buffer> <Plug>Pencilkeys_down gj
nnoremap <buffer> <Plug>Pencilkeys_AltDown j
...

And to shut off pencil mappings you can unbind the buffer local pencil mappings.

This should make unbinding everything clean. It solves the problem of reverting to a user's original bindings because you won't have to anymore.

I was going to suggest this as an enhancement, but this issue covers my problem and why I am doing this on my own, since my 0 and ^ weren't handled right.