===== Editing the command line ===== Bash (as well as numerous other programs) uses the [[https://en.wikipedia.org/wiki/GNU_Readline|readline]] library to read commands from standard input. \\ Lots of software use for the same purpose the [[https://thrysoee.dk/editline/|libedit]] library due to licensing reason. The readline library is renown for providing comfortable, efficient and powerful editing capabilities within the input line as well as its built-in support for history of previously read lines. A reasonable selection of keyboard shortcuts for line editing is available as [[https://readline.kablamo.org/emacs.html|a cheat sheet]]. \\ The full list of commands and key sequences bound to them is available in the system manual (''man readline'' i ''man bash''). \\ To write down the key sequences, the following syntax is used: * ''^//x//'' or ''C-//x//'' stands for //Ctrl+x// (watch out for upper case letter:''^//X//'' or ''C-//X//'' is //Ctrl+Shift+x//), * ''M-//x//'' usually maps to //Alt-x// (see https://en.wikipedia.org/wiki/Meta_key for more explanations), * ''//a// //b//'' stands for pressing key sequence //a// followed by key sequence //b//. Bash by default appends the history of commands to the file ''~/.bash_history'' upon exit. \\ History (read from the ''~/.bash_history'' file and extended by history of commands executed in current shell) can be displayed with the ''history'' command. (Consult ''man bash_builtins'' to learn its switches.) For a more convenient history browsing one can leverage the [[https://dvorka.github.io/hstr/|hstr]] command. ~~Exercise.#~~ What key combination clears the screen? ~~Exercise.#~~ What key combination search the history backwards and forwards? \\ (Be careful around the forward search key combination – it might overlap with flow control; if your terminal freezes, use ''^q'' to unfreeze it and issue ''stty -ixon'' to disable flow control.) ~~Exercise.#~~ What key combination moves the caret by one word (forward and backward)? ~~Exercise.#~~ Which key sequence moves the caret by five words? ~~Exercise.#~~ What key combination inserts ('yanks') last word of the previous line in the history? ~~Exercise.#~~ Which key sequence inserts ('yanks') third word (counting from the end) of the previous line in the history? ~~Exercise.#~~ What key combination transposes this word with the one preceding it? ===== Console text editors ===== === vi & vim === In many Linux distributions the only preinstalled text editor is the ''vi'' program. ''vim'' is an improved version of ''vi''. The ''vim'' editor is accompanied with a tutorial. To start it, one has to run the ''vimtutor'' command. ''vi'' is even a part of the [[https://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html|POSIX]] standard. \\ It is a part of minimalistic toolboxes such as busybox and toybox. ~~Exercise.#~~ Complete the first lesson of the ''vimtutor''. ~~Exercise.#~~ Complete all lessons of the ''vimtutor''. === nano === Nano is a text editor with basic functions that still suffice to accomplish most tasks painlessly. Basic keyboard shortcuts for nano are always displayed on the bottom of the screen. Fore fill documentation visit: https://www.nano-editor.org/docs.php === Emacs === [[https://www.gnu.org/software/emacs/|Emacs]] is an [[https://en.wikipedia.org/wiki/Editor_war|eternal rival]] of ''vim'' in the aspect of editing text files in terminal. After starting ''emacs'' one can start a tutorial using a key sequence //Ctrl+h t//. === Other === * [[https://joe-editor.sourceforge.io/joe]] * mcedit – built-in editor of [[https://en.wikipedia.org/wiki/Midnight_Commander|mc]] * [[https://micro-editor.github.io/|micro]] * [[https://neovim.io/|neovim]] * [[https://helix-editor.com/|hx]] ~~META: language = en ~~