rust-ssg/data/blog/posts/2014-06-21_readline.rst

44 lines
2.1 KiB
ReStructuredText
Raw Normal View History

2023-10-14 18:03:36 +00:00
Readline
########
:date: 2014-06-21 04:01
:author: tyrel
:category: Tech
:tags: readline, linux, cli
:slug: readline
:status: published
A lot of times when I stop at someone's computer and help them in the terminal, I use a Readline command and people say "How the heck did you do that?"
Let me first backup and explain what Readline is. From the GNU Readline Documentation - "The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in." By default, Readline is set up in Emacs mode, no you don't have to have an extra four fingers to use Readline, most of the commands are simple.
Here are a couple of the commands I use daily:
Movement
~~~~~~~~
- To move to the beginning of a line, you press ``C-a``
- To move to the end of a line you press ``C-e``
Killing and Yanking
~~~~~~~~~~~~~~~~~~~
- To cut the rest of the line from where your cursor is, to the end, you press ``C-k``
- To delete one word you press ``C-w``
- To paste either of the two previous back you can press ``C-y``
Miscellaneous
~~~~~~~~~~~~~
- To clear the screen and get to a fresh start, you can press ``C-l``
- To end your session you can send a ``C-d`` (This will send an end of file character)
- To search for a command you typed recently, press ``C-r`` and start typing, it will search backwards. ``C-r`` again will search for an earlier match.
- The inverse of ``C-r`` is ``C-s``, they function the same.
- To open your ``$EDITOR`` to edit the current shell command you wish to write, press ``C-x C-e``
Finally, don't forget about ``C-c``. While not specifically Readline, it's very useful because it sends the SIGINT signal to the program, which if just on the command line, will not execute the line you have type, and give you a new line with nothing on it. A nice clean start.
To find out a lot more, read the documentation at `the Readline Commands Docs <http://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html>`__ I even learned some things while writing this up, apparently pressing ``C-x $`` will list off all the possible usernames. Good to know, and good to always keep learning.