I would like to be able to copy and paste text in the command line in Bash using the same keyboard bindings that Emacs uses by default (i.e. using
M-w to copy text,
M-y to paste it, etc.).
The GNU Bash documentation says that Bash comes with some of these key bindings set up by default.
For example, yanking (
C-y) works by default on my terminal. However, I can't get the
copy commands to work, and they don't seem to be bound to any keys by default.
Usually, the way a user can define her own key bindings is to add them to
.inputrc. So I looked and found the following bash functions in the documentation that I presume can help me define the Emacs-like behavior that I want (i.e.
Copy the text in the region to the kill buffer, so it can be yanked right away. By default, this command is unbound.
Set the mark to the point. If a numeric argument is supplied, the mark is set to that position.
If I understand correctly, the above means that
copy-region-as-kill is not bound to any keyboard sequence by default, while
set-mark is bound to
C-@ by default.
C-@ on my terminal, but I don't think it runs
set-mark because I don't see any text highlighted when I move my cursor. In any case, I tried adding keyboard bindings (
C-) to the functions
set-mark above in my
.inputrc and then reloading it with
C-x C-r, but this didn't work. I know that my other entries in
.inputrc work because I have other user-defined keybindings defined in it.
Is there anything I am doing wrong? Am I missing anything?