This is a text-only version of the following page on https://raymii.org: --- Title : ed cheatsheet Author : Remy van Elst Date : 06-10-2012 URL : https://raymii.org/s/tutorials/ed_cheatsheet.html Format : Markdown/HTML --- > ed is a line editor for the Unix operating system. It was one of the first end-user programs hosted on the system and has been standard in Unix-based systems ever since. ed was originally written in PDP-11/20 assembler by Ken Thompson in 1971.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $200 credit for 60 days. Spend $25 after your credit expires and I'll get $25!

[Download the PDF cheatsheet][2] ## Navigating * Line number: go to that line and print it. * pn - _Print current line and line number._ * 3kxe - _mark line 3 as "xe"._ * 'xep - _print the line marked as xe._ ## Editing * a - _start editing after the current line._ * i - _start editing before the current line._ * c - _replace the current line._ * end the editing with only a period on a line (.). * 1d - _delete line 1._ * 1,2j - _join line one and two._ ## Printing * 1,$p - _print entire buffer._ * ,p - _also prints the entire buffer._ * 2,3p - _print lines 2 and 3._ * .,4p - _print from the current line (.) to line 4._ * -1,+1p - _print 1 line above and 1 line below the current line._ ## Buffer operations * 2t4 - _Copy line 2 to after line 4._ * 2t$ - _Copy line 2 to the end of the file._ * 3m6 - _Move line 3 to after line 6._ * 2,4m$ - _Move lines 2 to 4 to the end of the file._ ## Searching / replace * /like - _Move to the next line after the current one matching regular expression /like._ * ?Like - _Search backwards._ * 1s/re/jo - _Substitute only the first occurence of re with jo on line 1._ * 1s/re/jo/g - _Substitute all occurences of re with jo on line 1._ * 1,$s/re/jo/g - _Substitute all occurences of re with jo in the whole buffer._ ## Regular expresions * g/re/p - _print all the lines matching regular expression /re/._ * v/re/p - _print all the lines NOT matching regular expression /re/._ * g/re/m$ - _move all the lines matching regular expression /re/ to the end of the file._ ## Reading and writing * w file.txt - _Save the current buffer as filename file.txt._ * w - _Save the current buffer if the file is already saved._ * w1,4 - _Save lines 1 to 4 to the current buffer._ * W - _append to a file (not replace)._ * r /etc/hosts - _Insert the contents of /etc/hosts after the current line._ * r !ps -e - _Insert the output of the command "ps -e" after the current line._ * e file.txt - _Open the file file.txt and replace the current buffer._ [1]: https://www.digitalocean.com/?refcode=7435ae6b8212 [2]: https://raymii.org/s/inc/downloads/ed_cheatsheet.pdf --- License: All the text on this website is free as in freedom unless stated otherwise. This means you can use it in any way you want, you can copy it, change it the way you like and republish it, as long as you release the (modified) content under the same license to give others the same freedoms you've got and place my name and a link to this site with the article as source. This site uses Google Analytics for statistics and Google Adwords for advertisements. You are tracked and Google knows everything about you. Use an adblocker like ublock-origin if you don't want it. All the code on this website is licensed under the GNU GPL v3 license unless already licensed under a license which does not allows this form of licensing or if another license is stated on that page / in that software: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Just to be clear, the information on this website is for meant for educational purposes and you use it at your own risk. I do not take responsibility if you screw something up. Use common sense, do not 'rm -rf /' as root for example. If you have any questions then do not hesitate to contact me. See https://raymii.org/s/static/About.html for details.