Ubuntu – Shell with better editing capabilities

bashcommand linegnome-terminal

Shells (at least what I know) have really bad command editing capabilities.

For example:

  • I can't point the cursor to any point of the command.
  • I can't select and backspace/delete/replace text in the command.

Currently these are so distracting, I use gedit to edit commands before pasting them to the terminal.

Is there any solution that's good for these?

Best Answer

Bash is actually quite good at this. You just need to learn its shortcuts. For example (in the default emacs mode):

  • Ctrl + A : move to the beginning of the line.
  • Ctrl + E : move to the end of the line.
  • Ctrl + B : move one character backwards.
  • Ctrl + F : move one character forwards.
  • Alt + B : move one word backwards.
  • Alt + F : move one word forwards.
  • Ctrl + K : delete (cut) everything until the end of the line.
  • Alt + D : delete (cut) the word after the cursor.
  • Ctrl + W : delete (cut) the word before the cursor.
  • Ctrl + Y : yank (paste) what is in the buffer (what you cut with Ctrl+K or Alt + D for example)

And there are many more. Read man readline to see what else is available. You can assign different shortcuts by placing them in ~/.inputrc. For example, to make Ctrl + Left go back one word and Ctrl + Right go forward one word, add this to your ~/.inputrc:

"\e[1;5D": backward-word 
"\e[1;5C": forward-word

To find out what those strange codes mean, press Ctrl + V and then press the key you would like to use. If you try with Ctrl + Right, you will see ^[[1;5C. Replace ^[ with \e in ~/.inputrc.


You might also want to look into other shells. Popular "modern", feature-rich shells include:

Related Question