Check out the console snippet editor [snip](https://github.com/genotrance/snip) I did a few months ago. It's far from perfect but works well enough.
The code is mainly in [key.nim](https://github.com/genotrance/snip/blob/master/src/snip/key.nim) and [keymap.nim](https://github.com/genotrance/snip/blob/master/src/snip/keymap.nim).
