Most shells that have a command line editing feature
support Emacs key bindings. (a tiny subset)
Up Ctrl+P
Down Ctrl+N
Left Ctrl+B
Right Ctrl+F
Home Ctrl+A
End Ctrl+E
Delete Ctrl+D
Alternatively, you could set up your shell to use vi command editing mode, by addingset -o vi
to your shell startup file (e.g., ~/.bashrc
).
Then, for example, you can- Use Esc k Enter
to re-execute the previous command (same as
!!
). The minus key - also works as a "move up" command. - Use Esc k k k k k k k k k k k kEnter
or Esc 12 k Enter
to re-execute the 12th previous command (same as
!-12
). - Use Esc and a motion command
(i.e., k, suitably repeated),
and then edit the bash command line you find there.
Remember, you will still be in
vi
command mode, so you will need to use avi
editing command (e.g., I, A, C, R, or one of their lowercase counterparts) to actually add to the command from history.
So, for example, Esc k i sudo Space Enter is equivalent tosudo !!
. - For advanced users: you can even copy (yank) text from one line
and paste (put) it on another,
so you can accomplish results comparable to
!-2:- !$
. (Unfortunately, it does not seem to support named buffers.)
Source: about article is copied from here
Comments
Post a Comment