104 lines
No EOL
3.8 KiB
Text
104 lines
No EOL
3.8 KiB
Text
= Ed text editor cheat sheet
|
|
:author: Yuri Slobodyanyuk
|
|
|
|
Author: Yuri Slobodyanyuk, https://linkedin.com/in/yurislobodyanyuk/ .
|
|
|
|
STATUS: Work in progress.
|
|
|
|
NOTE: The cheat sheet is for GNU version of `ed`. All values in [] are optional. `ed` fully supports Unicode.
|
|
|
|
.Command mode
|
|
[cols=2,options="header"]
|
|
|===
|
|
|
|
|Command
|
|
|Description
|
|
|
|
|*[_n_]a*
|
|
| Append - append a new line after the current , or, if _n_ is given, after the _nth_ line, then enter input mode. Use 0 (zero) for _n_ to append at the top of the buffer.
|
|
|
|
|*[_n_]i*
|
|
|Insert - insert a new line before the current or the _nth_ line, if given, then enter the input mode. Use 0 as _n_ to insert at the top of the buffer
|
|
|
|
|*[_n_]c*
|
|
|Change - change the current, or the _nth_ line if given, then enter the input mode. The current (or specified) line gets deleted before you start typing a new one.
|
|
|
|
|*[_start,end_]m[_dest_]*
|
|
|Move lines, including, from _start_ up to the _end_ after the _dest_ destination line.
|
|
|
|
|*[_start,end_]t[_dest_]*
|
|
| Transfer - copy lines _start_ through _end_ after the _dest_ line. If no line numbers are given, copies the current line and pastes underneath.
|
|
|
|
|*e [_filename_]*
|
|
|Edit a file - _filename_ if given, default if not.
|
|
WARNING: Current buffer and all of its changes are discarded.
|
|
|
|
|*[_start,end_]w [_filename_]*
|
|
| Write the current buffer (whole or just lines between _start_ and _end_) to a _filename_ if given or the currently set with the `file` command. The contents of the _filename_ is overwritten! Ed reports number of characters written on success.
|
|
|
|
|*[_start, end_]W [_filename_]*
|
|
|Write by appending the buffer to the file _filename_, the current contents of the _filename_ are not overwritten. Ed reports number of characters written on success.
|
|
|
|
|*[.]=*
|
|
| Show number of lines in the buffer, or, if `.` (dot) is given `.=`, show the line number of the current line.
|
|
|
|
|*P*
|
|
|Show/hide prompt, * (asterisk) is the default.
|
|
|
|
|*H*
|
|
|Turn on/off verbose error indication mode. With this mode off, `ed` only outputs `?` for any error without additional info.
|
|
|
|
|*! _shell command(s)_*
|
|
| Run the given _shell command(s)_ displaying their output without leaving the `ed`. Hitting <Enter> returns to the `ed` buffer. The shell's output is not kept or redirected to the buffer in any way.
|
|
|
|
|*r*
|
|
|Read
|
|
|
|
|*r !_shell command(s)_*
|
|
|Run the shell command
|
|
|
|
|*[_start_,_end_]p*
|
|
| Print lines from _start_ to _end_ or current if not set. Sets current line to the last line printed.
|
|
|
|
|*q*
|
|
|Quit the `ed`, warns if there are unsaved changes, if repeated 2nd time, quits discarding any unsaved changes.
|
|
|
|
|*Q*
|
|
|Quit `ed` unconditionally, discarding any unsaved changes.
|
|
|
|
|*u*
|
|
|Undo the last change. `ed` has only one level of uno, entering `u` the second time redoes the change undone before.
|
|
|
|
|*_n_*
|
|
|Go to the line _n_.
|
|
|
|
|*[_starting_address_]z[_lines-to-scroll_]*
|
|
| Scroll default 24 lines down, if _lines-to-scroll_ is not given. Optionally, start scrolling not from the current line (default), but from the line number _starting_address_. Resets current line to the last line after scrolling position.
|
|
|
|
|
|
|*[_start_,_end_]n*
|
|
|Print _start_,_end_ lines prefixed by their line number, analog of *p* but prints line numbers as well. Use `,n` to print the whole buffer with line numbers.
|
|
|
|
|*[_start_, _end_]s/_regex_/_replacement_/[g]*
|
|
|Substitute - on lines _start_ to _end_, find 1st occurrence of _regex_ from the left (or all the occurrences if `g` for Global prefix is added) and replace with the _replacement_.
|
|
|
|
|===
|
|
|
|
.Input mode
|
|
[cols=2, options="header"]
|
|
|===
|
|
|
|
|Command
|
|
|Description
|
|
|
|
|*.* (dot on a line by itself)
|
|
|Switch from input to the command mode. The . (dot) should be entered on a new line by itself, then <Enter>.
|
|
|
|
|
|
|*CTRL + C*
|
|
|Discard the changes done in the current input mode sequence, and return to the command mode. Only changes since entering last input mode are discarded, not the whole session.
|
|
|
|
|
|
|
|
|
|
|=== |