Skip to content

GNU Readline: The Hidden Hero of Your Terminal ๐Ÿฆธ

Readline is widely used but less widely understood.

Most Used Readline Commands

Function Name Shortcut Description ๐Ÿ’ญ
๐Ÿ” reverse-search-history Ctrl-R Search command history backwards The ultimate history finder
โฌ…๏ธ beginning-of-line Ctrl-A Move to start of line Faster than holding left arrow
โžก๏ธ end-of-line Ctrl-E Move to end of line Better than mashing right arrow
๐Ÿฆ˜ forward-word Alt-F Move forward one word Like Ctrl-Right in editors
๐Ÿฆ˜ backward-word Alt-B Move backward one word Like Ctrl-Left in editors
โœ‚๏ธ unix-word-rubout Ctrl-W Delete word before cursor Quicker than backspace
๐Ÿ—‘๏ธ kill-line Ctrl-K Kill text from cursor to end Perfect for rewriting commands
๐Ÿ“‹ yank Ctrl-Y Yank previously killed text Paste what you just cut
๐Ÿงน clear-screen Ctrl-L Clear screen Cleaner than typing 'clear'
๐ŸŒŸ yank-last-arg Alt-. Insert last arg of previous command Great for operating on same file
โ†ฉ๏ธ undo Ctrl-_ Undo Everyone needs an undo!
๐Ÿ“ insert-comment Alt-# Comment line & move to new line Save that command for later
๐Ÿ”„ exchange-point-and-mark Ctrl-XX Toggle between start & cursor Great for adding sudo
๐ŸŽฏ character-search Ctrl-] x Move to next character 'x' Quick character navigation
๐Ÿ“œ beginning-of-history Alt-< Move to first command in history Jump to the beginning
๐Ÿ“œ end-of-history Alt-> Move to last command in history Back to the present

Pro Tips ๐ŸŽ“

  • These function names are what you'll see in the output of bind -p
  • Use them in your .inputrc for custom bindings
  • They're consistent across readline-using applications
  • Many have both emacs and vi mode equivalents

Notes

$ llm cmd "gnu readline: delete from cursor to end of lines"
> bind-key -x '"\C-k": kill-line'