pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

How to change default key bindings / hotkeys or assign new bindings

Open shitcoding opened this issue 2 years ago • 4 comments

Hi! First of all, thanks for an amazing tool that helps a lot!

I have a small question: Are there any ways to change default key bindings, or assign new ones? For example, use ctrl-j / ctrl-k to navigate up / down dropdown autocompletion list (instead of default tab / shift-tab)

I looked for a solution in pgcli docs, googled for a while, but didn't find anything.

Thanks in advance!

shitcoding avatar Aug 30 '23 13:08 shitcoding

Hi @shitcoding ,

There's no easy way to modify or add new keybindings. We have an open issue that discusses this:

  • https://github.com/dbcli/pgcli/issues/760

For now, people resort to patch their local pgcli/key_bindings.py. I agree that this is not ideal. I'll take a look and see what it takes to add custom keybinding functionality to pgcli; you're not the first person to need this.

j-bennet avatar Aug 31 '23 00:08 j-bennet

That should be better done at the prompt-toolkit layer, IMO.

lelit avatar Aug 31 '23 06:08 lelit

That should be better done at the prompt-toolkit layer, IMO.

Yes, we thought so too. But in the meantime, we could take the same approach as ptpython, like @jonathanslenders advised here:

https://github.com/dbcli/pgcli/issues/760#issuecomment-618016523

Eventually, python_prompt_toolkit may support .inputrc, and we could switch the approach:

https://python-prompt-toolkit.readthedocs.io/en/stable/pages/advanced_topics/key_bindings.html#processing-inputrc

j-bennet avatar Sep 01 '23 00:09 j-bennet

Thanks for your help! Got to try these approaches, hope it will relieve my vim nerd pain ;)

shitcoding avatar Sep 01 '23 16:09 shitcoding