Shell with better editing capabilities

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:

  • zsh
  • fish
  • ksh

You can edit an empty or partially typed command into the editor of your choice by setting EDITOR to the editor of your choice and by hitting CTRL+X+E or CTRL+X/CTRL+E, which open the currently being edited line in EDITOR;

For example, setting EDITOR to gedit will make CTRL+X+E and CTRL+X/CTRL+E open the current line in Gedit.

To make this a permanent solution, you can set EDITOR in ~/.bashrc.

This allows to use even a fully-fleged graphical text editor to edit the command; to run the edited command, simply save and close the document.


The same feature can be enabled in Zsh by adding the following to ~/.zshrc:

autoload -U edit-command-line
zle -N edit-command-line
bindkey '^xe' edit-command-line
bindkey '^x^e' edit-command-line

Terminals have no text editing abilities themselves. Terminals provide an area of text and connect the keyboard to something. But the something that you run inside the terminal determines what it can do.

Shells such as bash are typically the first thing that you will find to run inside of a terminal. Because shells work based on commands you are only able to edit the current command. bash provides excellent command editing compared to the Bourne shell or csh or ksh yet it is hardly something you would want to edit even a short story with.

Text editors are one of the commands you can invoke in the shell. The leading examples are vim and emacs. vim or emacs will give you the ability to edit almost anything. Both include built-in programming environments for extending their abilities to whatever problem you face.

So the solution is to understand better what these tools are doing and meant to do and pick the right one for the job.