.Dd Created:2025-10-03|Updated:2025-11-27| .de ocsi \\$* , .. .de oxr .ocsi .Xr \\$* .. .de oit .It \\$* .. .de obdi .Bl -dash -compact .oit \\$* .. .de obdl .Bd -literal -compact \\$* .. .de onote .Bl -hang -compact .oit \\$* .El .. .de ocomm .Bl -diag -compact .oit \\$* .El .. .de opsy .Pp .Sy - \\$* .. .de obc .Bl -column \\$* .. .de obc2 .obc opt desc .. .de obc3 .obc option arguments description .. .Dt ED oh .Os OpenBSD 7.8 , linux | .Nm ed .Nd text editor : usage .Sh TOC .Bl -column -offset indent "Sy - It - Sx searching " ".Sy - It - Sx searching " .It Sx COMMANDS .It - Sx general .It - Sx address .It - Sx print .It - Sx edit .It - Sx marks .It - Sx files .It - Sx searching .It - Sx interactive_edit .It - Sx important .It - Sx shell_commands .It Sx SPLIT_LINES .It Sx SCRIPTING .It - Sx example .It Sx SEE ALSO .El .ocomm NOTE: this document is based on OpenBSD ed, there may be some differences on GNU ed. .Sh COMMAND LINE .obc2 .It -p Ta | specify prompt. Eg.: -p : .El .Sh COMMANDS [range]command .Ss general .obc2 .It P Ta | toggle prompt. .It q Ta | quit. Warns if the buffer has been modified. .It Q Ta | quit regardless of whether any changes have been made to the buffer. .It h Ta | explain last error. .It H Ta | toggle error explanation. .It u Ta | undoes the last command. .It = Ta | print total lines. .El .Ss address Most commands require a range on which to be executed. If no range is specified, it defaults to the current range. .D1 Exceptions: u (undo), z (scroll), h (help messages). .Bl -column ".Sy - opt " .It n Ta : 6 .It n,n Ta : 4,5 .It + Ta : next line. .It - Ta : previous line. .It \&. Ta : current line. .It $ Ta : last line. .It +n Ta : address at n lines after current line. .It -n Ta : address at n lines before current line. .It ; Ta : from current line to the end. .It /pattern/ Ta : next line matching pattern. // repeats last search. .It ?pattern? Ta : previous line matching pattern. ?? repeats last search. .El .Ss print .Bl -column ".Sy - -opt " .It p Ta : print addressed lines. .It n Ta : print addressed lines with line numbers. .It l Ta : print addressed lines including control and non-printable characters. .El .Ss edit .Bl -column ".Sy - opt " .It a Ta : append: start adding text after the range. (Eg.: 4a) .It i Ta : insert: start adding text before range. (Eg.: 4i) .It c Ta : change: change the addressed line. (Eg.: 4c) .It d Ta : delete: deletes range. (Eg.: 4d) .It m Ta : move: move source range after target range. (Eg.: 4m5 ) .It t Ta : copy (transfer): copy source range after target range. (Eg.: 4t6) .It j Ta : join: join addressed lines. (Eg.: 4,5j) .El .Ss marks .Bl -column ".Sy - opt " .It kl Ta : mark an range with a lower-case letter. (Eg.: 4ka) .It 'l Ta : set current range to the range marked as l. ( Eg.: 'a > will set current range to 4) .El .Ss files .Bl -column ".Sy - [address]w [address] " ".Sy description " .It e [filename] Ta : edit file, if no file is specified it reloads the current file. .It E Ta : same as e but discards changes if any. .It w [file] Ta : writes file. If file is not specified, it writes the current file. .It [range]w [file] Ta : writes specified range to file or current file if no file is specified. .It [range]W [file] Ta : same as w but appends to filename if the file exists. .It % Ta : represents the current file. .It f Ta : sets/shows the current filename. .It r [file] Ta : reads file into buffer at the end. .It [range]r [file] Ta : reads file into buffer after range. .El .Ss searching .Bl -column ".Sy - opt " .It g Ta : search globally for matches. .It v Ta : search globally for non-matching lines. .El .Ss interactive_edit Commands G and V work the same as the lower case version, but edits each match interactively. .Bl -enum -compact .It G/re/ .It Returns the first match. .It User edits the match. .It ed displays the next match. .It The user can edit the match or enter & to repeat the last non-empty command list. .El .obdl $ ed -p : :a line 1 line 2 line 3 \&. :G/l/ line 1 s/n/a/ line 2 s/e/o/ line 3 & :,n liae 1 lino 2 lino 3 .Ed .Ss important .Bl -column ".Sy - opt " .It s Ta : normally, substitution is called with /pattern/, but any character can be used (Eg.: |pattern| or @pattern@). .D1 this is useful when substituting paths or variables. .It z[n] Ta : scroll. .obdi if n is specified, scroll the number of lines specified by n. .oit If n is not specified and zn has been run before, remember the number of lines used before. .oit if n is not specified and zn has not been run before, scroll the number of lines determined by the terminal size. .oit n: add n to show line numbers. (Eg.: z5n) .El .El .Ss shell_commands The following commands can be used with shell commands: .obc o write_addressed_Lines_Into_command desc .It e Ta : edit output of command Ta : Li e !command .It r Ta : read output of command into buffer Ta : Li [range]r !command .It w Ta : write addressed lines into command. Ta : Li [range]w !command .El .obdl $ ed -p : :e !ls :,n dir1 dir2 :r !ls dir1 :,n dir1 dir2 file1 :w !xargs -n1 echo dir1 dir2 file1 .Ed .Sh SPLIT_LINES .obdl $ ed t a hello bye \&. w 10 w !awk 'sub("o ","o\en",$0);' > % e 10 ,n hello bye .Ed .Sh SCRIPTING .onote NOTE: It's important to always have the . and w on any interactive commands. .D1 To add a \&. on a script without ending the input, enter \e\&. and then substitute the \e\ : .Li ,s@^\e\e\&.$@\&.@ .Ss example .obdl $ ed script a a this line is appended \e\&. w \&. ,s@^\e\e\&.$@\&.@ w q $ cat script a this line is appended \&. w $ cat test.txt line 1 $ ed - test.txt < script $ cat test.txt line 1 this line is appended .Ed .Sh SEE ALSO .opsy OpenBSD manpages: .Xr ed 1 .El .Ss links .obc2 .It - Lk https://dataswamp.org/~solene/2018-12-04-fun-splitting-line.html Solene - ed split lines .It - Lk https://github.com/ibara/oed Linux port - OpenBSD ed at GitHub .It - Lk https://www.gnu.org/software/ed/ed.html GNU ed .It - Lk http://sam.cat-v.org/ sam - multi-file text editor .It - Lk https://edbrowse.org/ Edbrowse, a Command Line Editor Browser .It - Lk http://man.cat-v.org/unix-1st/1/ed man.cat-v ed(1) - Unix First Edition Manual Page .It - https://www.gnu.org/software/diffutils/manual/html_node/Detailed-ed.html GNUed Detailed ed (Comparing and Merging Files) .It - Lk https://www.gnu.org/software/diffutils/manual/html_node/Example-ed.html Example ed (Comparing and Merging Files) .It - Lk https://www.gnu.org/software/diffutils/manual/html_node/ed-Scripts.html ed Scripts (Comparing and Merging Files) .It - Lk https://www.unix.com/shell-programming-and-scripting/233897-ed-command-execution-script-file.html unix.com - Ed command execution in script file .El .Sh AUTHORS .An -nosplit .Xr ohazot oh | .Xr about oh | .Lk https://ohazot.com ohazot.com .Aq Mt admin@ohazot.com