Adding Ctrl-L as "clear" hotkey in OpenBSD's ksh

5,334

Solution 1

According to the OpenBSD ksh man page, Ctrl+L is bound to redraw.

 redraw: ^L
         Reprints the prompt string and the current input line.

If that isn't sufficient, I can't see any editing command that will help, so I would suggest learning more about bind -m.

Perhaps you can do something like bind -m '^L'=clear'^J' to make it type clear Enter.

Solution 2

You should be able to add an alias to your .kshrc to do this. Try

alias "^L"=clear

Where ^L is the single char Ctrl-L. You might not need the quoting, if it still doesn't work the last resort would be to escape it like (what you are typing, not what will be visible in your file) Ctrl-VCtrl-L→clear.

IHTH

Share:
5,334

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    I've been looking for a way to use Ctrl-L to clear the monitor instead of typing clear in each time. I found nothing except a patch which didn't work for me. How do I add hotkeys/shortcuts to my OpenBSD box (which uses ksh as a shell)?

    [*] OpenBSD's ksh.kshrc

    [*] Ctrl-l in hex = 0xc :

    # read key ; echo -n $key > file.txt ; hexdump file.txt
    ^L
    0000000 000c                                   
    0000001
    # 
    
  • kjo
    kjo about 13 years
    Thank you shellter but this way works for bash not ksh.
  • Mikel
    Mikel about 13 years
    I have tested bind -m '^L'=clear'^J' on OpenBSD 4.9 and it works.
  • Wiliam
    Wiliam about 13 years
    It's solved, Mikel & shellter thank you for help.
  • XGouchet
    XGouchet about 13 years
    @Barakat : What isn't working? What is the error message? It works in my ksh environment ;-) (and I'm sure it would have worked where I used Solaris and AIX ksh's). Hmm. re-read your posting and see you're refering to OpenBSD ksh. Sorry I don't have experience with that. Is it possible that it is really pdksh? Good Luck.
  • XGouchet
    XGouchet about 13 years
    @Barakat : One other thing, did you restart your shell after adding alias defintion to .kshrc. Or you could add it to ~/.profile and then start a new shell.