G-code commands you will actually edit, and the trap in each one
By Sina Esfahani, OmniTechs · Published 27 November 2026
G-code is the text file your slicer writes. Each line holds one command, such as G28 or M104, followed by values such as S210. Everything after a semicolon is a comment.
You only ever edit a handful of commands, mostly in the start code, the end code or at one layer. They look universal, but the firmware decides what each one does, and Marlin, Klipper, Prusa and Bambu Lab differ on details such as whether homing keeps your bed mesh. Look a command up for your firmware before you paste forum code, change one line at a time, and watch the first test print.
Before you edit a line, do this in order:
Find out which firmware reads the file: Marlin, Klipper, Prusa (MK3 or Buddy) or Bambu Lab.
Copy the whole start code into a text editor and keep the original.
Start heaters with M104 and M140; use M109 and M190 only where the printer must wait.
Put G90 before M83: on Marlin, G90 cancels relative extrusion.
Reset the extruder with G92 E0 before and after every prime or purge.
After G28 on Marlin, load a saved mesh with M420 S1; on Klipper, use BED_MESH_PROFILE LOAD=default.
Run the first print with your hand near the power switch.
What you see after an edit, and what it means
Symptoms after editing G-code
| What you see | What it means | What to do |
|---|---|---|
| The printer sits still for minutes at the start | An M109 or M190 is waiting for a temperature | Start both heaters early with M104 and M140; wait only where you need the heat |
| The extruder pulls filament back instead of priming | Absolute extrusion without a G92 E0 reset | Add G92 E0 before and after the prime |
| The bed mesh is ignored after homing (Marlin) | G28 switches levelling off by default | Add M420 S1 after G28 |
| The saved mesh is ignored (Klipper) | Klipper stopped loading a profile at start-up in February 2023 | Add BED_MESH_PROFILE LOAD=default to the start macro |
| Klipper rejects G29 or M600 | Neither is built into Klipper | Use BED_MESH_CALIBRATE, or define a macro |
| M600 does nothing, or the printer waits for ever (Marlin) | Filament change is not built in, or nothing can confirm it | It needs Advanced Pause and a display button, or a host that sends M108 |
| M106 S50 gives a weak fan | The value runs from 0 to 255, not in percent | Use S128 for about half and S255 for full |
| Prints keep the speed last set on the screen | The speed override stays until reset | Put M220 S100 in the start code |
The commands at a glance
The G-code commands people edit most
| Command | What it does | Example | Watch out for |
|---|---|---|---|
| G28 | Homes the axes, all of them if no letter follows | G28 or G28 X Y | On Marlin it switches bed levelling off |
| G29 | Probes the bed and builds a mesh | G29 | Means something different per firmware; not built into Klipper |
| G92 | Tells the printer where it is, without moving | G92 E0 | Mostly used to set the extruder count to zero |
| M104 | Sets the nozzle temperature and carries on | M104 S210 | The next lines run while the nozzle still heats |
| M109 | Sets the nozzle temperature and waits | M109 S210 | On Marlin, S waits only while heating |
| M140 and M190 | Bed temperature, without and with waiting | M140 S60, later M190 S60 | On Marlin, M190 with no value does nothing |
| M106 and M107 | Part-cooling fan on at a speed, and off | M106 S128, M107 | Speed runs from 0 to 255 |
| G4 | Pauses for a set time | G4 P500 or G4 S2 | P is milliseconds, S is seconds; Klipper documents only P |
| M600 | Starts a filament change | M600 | Only if built in or defined as a macro |
| M82 and M83 | Extruder in absolute or relative mode | M83 | On Marlin, a later G90 or G91 cancels it |
| M220 and M221 | Speed and flow override in percent | M220 S100 | S100 undoes a change made on the screen |
CNC Kitchen works through the same commands in order, one chapter each.
M104 or M109: when should the printer wait?
M104 and M140 set a target and move straight to the next line. M109 and M190 hold the file until the target is reached. A fast start uses both: start the heaters without waiting, home while they warm up, and wait just before the heat is needed.
The waiting rules differ per firmware:
Marlin: M109 with S waits only while heating. With R it also waits while the nozzle cools to the new target.
Klipper: M109 and M190 always wait until the temperature settles at the value you asked for, up or down.
Prusa MK3 family: the reference says S and R both wait both ways; a comment on that page says the code now follows Marlin. Do not rely on either.
A worked example of the Marlin trap: your nozzle is at 210 °C and you want to wait until it has cooled to 150 °C before a move. M109 S150 returns at once, because S only waits for heating. M109 R150 waits until the nozzle is down to 150 °C.
For a plain pause, use G4: G4 P60000 waits one minute, because P counts milliseconds, as an accepted answer on the 3D Printing Stack Exchange explains. M400 is different: it waits until the moves already queued have finished, which is what you want before a beep or a message.
On Marlin, a waiting M109 or M190 also blocks commands from a host such as OctoPrint, unless the emergency parser is enabled so the host can break in with M108.
G92 E0 and absolute or relative extrusion
The extruder is one more axis, E. In absolute mode (M82), each E value is a position: the total length of filament fed so far. In relative mode (M83), each E value is the length for that one move. A move without a new E value extrudes nothing. G92 E0 sets the E position to zero without moving, which is why start code is full of it.
A worked example: you prime 3 mm in absolute mode with G1 E3 and do not reset. The next printing move says E0.5. The printer moves from E3 to E0.5 and retracts 2.5 mm instead of extruding 0.5 mm. Put G92 E0 after the prime and the same line extrudes 0.5 mm as intended.
Two firmware details cause most of the remaining mistakes:
Marlin: M82 and M83 only last until the next G90 or G91, which clear the extruder mode. Write G90 first and M83 after it, as Prusa's own MK4S profile does.
Klipper: M83 keeps the extruder relative even under G90. M82 only switches that forced relative mode off.
Your slicer has its own setting for the rest of the file:
PrusaSlicer: Printer Settings > General > Advanced > Use relative E distances (expert mode). PrusaSlicer writes G21, G90 and M82 or M83 itself, right after your start code.
OrcaSlicer and Bambu Studio: Printer settings > Basic information > Advanced > Use relative E distances. Bambu Studio greys it out for Bambu Lab printers.
Cura: Special Modes > Relative Extrusion, off by default. Cura sets absolute mode before any of your start code runs.
So write the E values in your own start code for the mode you set at the top of it, and let the slicer setting decide the rest.
Maker's Muse covers G92 and M83 in one chapter of a longer video; the link starts there.
G28, G29 and M420: homing and the bed mesh
G28 is in nearly every start code; G29 varies most. On Marlin, G29 runs whichever of five levelling systems was built in, and a plain G28 switches levelling off unless the firmware was built to restore it. Hence M420 S1 after G28: it switches the saved mesh back on. M420 S does the same, because Marlin reads a missing on-or-off value as on.
Do you need G29 before every print? Not if nothing has changed the bed: probe once, save the mesh with M500 and load it with M420 S1 in the start code (accepted answer, 3D Printing Stack Exchange). Probe again after the bed has been knocked or adjusted, or for a very different bed temperature that bends the plate differently.
On Klipper, the mesh command is BED_MESH_CALIBRATE. Adding ADAPTIVE=1 probes only the area the objects in the file use; Klipper says such a mesh is made fresh for each print and should not be saved. Tramming versus a mesh, and when to measure again, is in the bed levelling guide. The nozzle height itself is in the z-offset guide.
Where the firmware references disagree
| Command | Marlin | Klipper | Prusa MK3 family | Prusa Buddy (MK4, MK3.5, XL, MINI) |
|---|---|---|---|---|
| G28 with no letters | Homes all axes; levelling off afterwards by default | Homes all axes | Homes and runs mesh bed levelling; G28 W only homes | Homes without mesh bed levelling |
| G29 | Depends on the levelling system built in | Not built in; use BED_MESH_CALIBRATE or a macro | Switched off by default; the mesh command is G80 | Clears the old mesh and runs mesh bed levelling |
| Use a saved mesh | M420 S1 | BED_MESH_PROFILE LOAD=default | Measured during G28 or G80 | Prusa's profiles probe the print area each time |
| M109 | S waits only while heating; R both ways | Always waits until settled | Documented as waiting both ways; a reader comment says it now follows Marlin | Marlin-compatible, per Prusa |
| M190 with no value | Does nothing | Documented with an S value only | Waits for the target set earlier | Marlin-compatible, per Prusa |
| M600 | Needs Advanced Pause and a display, or a host sending M108 | Example macro in Klipper's sample configuration | Built in; parks at X 211, Y 0 and lifts 2 mm | Built in, with position and length options |
M106, M600 and M220: fan, filament change and speed
The part-cooling fan takes a speed from 0 to 255, not a percentage. To turn a percentage into a value, multiply by 2.55: 40 percent is S102, 50 percent is S128 and full speed is S255. M106 without a value runs the fan at full speed on Marlin and Prusa firmware; M107 switches it off. For Bambu Lab printers, a long-running Bambu Lab forum thread lists M106 P1, P2 and P3 for the part, auxiliary and chamber fans; those are users' findings, not a Bambu reference.
M600 is only as good as the firmware behind it:
Marlin needs its Advanced Pause feature, a nozzle park position and a way for you to say "continue": a display with a button, or a host that can send M108.
Klipper has no built-in M600. Its sample configuration defines one as a macro that saves the position, pauses, lifts the nozzle, moves aside and pulls the filament back 50 mm.
Prusa firmware has M600 built in.
To change colour or drop in a nut at one layer, the pause at height guide covers the slicer side and safe pause positions.
M220 S100 resets the speed to 100 percent if someone turned it up on the screen. Marlin applies M220 to every move on every axis. M221 S100 does the same for flow.
How to edit without breaking the printer's own code
Klipper does not aim to support every G-code command and lets you define the rest as macros. The same Bambu Lab forum thread warns that Bambu does not implement every Marlin command. Treat a command that is not in your firmware's reference as doing nothing until you have seen it work.
A safe way to work:
Start from the code your slicer ships for your printer, not a snippet for another machine.
Edit a copy in a text editor and paste the whole block back, as Bambu Lab's wiki asks, so you do not alter other lines by accident.
Change one thing at a time and comment each line you touch.
Try a single command first from a host terminal, such as OctoPrint's Terminal tab.
Stand next to the printer for the first test print.
When to stop
Switch the printer off if an edited line drives the nozzle into the bed or an axis against its end. Never send a command that switches off a safety feature to silence an error, such as M310 S0, which disables the thermal model on Prusa MK3 printers. If a command does not behave as your firmware's reference says, ask the printer maker's support rather than trying another forum snippet.
Next steps and related guides
To put these commands together at the start and end of a print, with heating order, purge line and slicer placeholders, go to the start and end G-code guide. To weigh Marlin, Klipper or the stock firmware, see the printer firmware guide.
Sources
Prusa Knowledge Base: Prusa firmware-specific G-code commands
Prusa Knowledge Base: Buddy firmware-specific G-code commands
3D Printing Stack Exchange: How do the E commands in G-code work, exactly?
3D Printing Stack Exchange: Using auto-bed leveling, do I need to initiate G29 before every print?
3D Printing Stack Exchange: What is the difference between M420 S and M420 S1?
3D Printing Stack Exchange: G-Code for resetting to 100% speed

