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:

  1. Find out which firmware reads the file: Marlin, Klipper, Prusa (MK3 or Buddy) or Bambu Lab.

  2. Copy the whole start code into a text editor and keep the original.

  3. Start heaters with M104 and M140; use M109 and M190 only where the printer must wait.

  4. Put G90 before M83: on Marlin, G90 cancels relative extrusion.

  5. Reset the extruder with G92 E0 before and after every prime or purge.

  6. After G28 on Marlin, load a saved mesh with M420 S1; on Klipper, use BED_MESH_PROFILE LOAD=default.

  7. 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

From the Marlin, Klipper and Prusa G-code references and Klipper's configuration changes log, read 27 November 2026.
What you seeWhat it meansWhat to do
The printer sits still for minutes at the startAn M109 or M190 is waiting for a temperatureStart both heaters early with M104 and M140; wait only where you need the heat
The extruder pulls filament back instead of primingAbsolute extrusion without a G92 E0 resetAdd G92 E0 before and after the prime
The bed mesh is ignored after homing (Marlin)G28 switches levelling off by defaultAdd M420 S1 after G28
The saved mesh is ignored (Klipper)Klipper stopped loading a profile at start-up in February 2023Add BED_MESH_PROFILE LOAD=default to the start macro
Klipper rejects G29 or M600Neither is built into KlipperUse 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 itIt needs Advanced Pause and a display button, or a host that sends M108
M106 S50 gives a weak fanThe value runs from 0 to 255, not in percentUse S128 for about half and S255 for full
Prints keep the speed last set on the screenThe speed override stays until resetPut M220 S100 in the start code

The commands at a glance

The G-code commands people edit most

Meanings from the Marlin and Klipper G-code references, read 27 November 2026. The F value in a G1 move is a speed in millimetres per minute: F1500 is 25 mm/s.
CommandWhat it doesExampleWatch out for
G28Homes the axes, all of them if no letter followsG28 or G28 X YOn Marlin it switches bed levelling off
G29Probes the bed and builds a meshG29Means something different per firmware; not built into Klipper
G92Tells the printer where it is, without movingG92 E0Mostly used to set the extruder count to zero
M104Sets the nozzle temperature and carries onM104 S210The next lines run while the nozzle still heats
M109Sets the nozzle temperature and waitsM109 S210On Marlin, S waits only while heating
M140 and M190Bed temperature, without and with waitingM140 S60, later M190 S60On Marlin, M190 with no value does nothing
M106 and M107Part-cooling fan on at a speed, and offM106 S128, M107Speed runs from 0 to 255
G4Pauses for a set timeG4 P500 or G4 S2P is milliseconds, S is seconds; Klipper documents only P
M600Starts a filament changeM600Only if built in or defined as a macro
M82 and M83Extruder in absolute or relative modeM83On Marlin, a later G90 or G91 cancels it
M220 and M221Speed and flow override in percentM220 S100S100 undoes a change made on the screen

CNC Kitchen works through the same commands in order, one chapter each.

Learn G-Code for 3D Printing (CNC Kitchen)

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.

Top 10 useful G-Code commands for 3D Printing (Maker's Muse)

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

From the Marlin, Klipper and Prusa (MK3 and Buddy) G-code references, Klipper's bed mesh page and Prusa's MK4S profile, read 27 November 2026. Bambu Lab publishes no full reference.
CommandMarlinKlipperPrusa MK3 familyPrusa Buddy (MK4, MK3.5, XL, MINI)
G28 with no lettersHomes all axes; levelling off afterwards by defaultHomes all axesHomes and runs mesh bed levelling; G28 W only homesHomes without mesh bed levelling
G29Depends on the levelling system built inNot built in; use BED_MESH_CALIBRATE or a macroSwitched off by default; the mesh command is G80Clears the old mesh and runs mesh bed levelling
Use a saved meshM420 S1BED_MESH_PROFILE LOAD=defaultMeasured during G28 or G80Prusa's profiles probe the print area each time
M109S waits only while heating; R both waysAlways waits until settledDocumented as waiting both ways; a reader comment says it now follows MarlinMarlin-compatible, per Prusa
M190 with no valueDoes nothingDocumented with an S value onlyWaits for the target set earlierMarlin-compatible, per Prusa
M600Needs Advanced Pause and a display, or a host sending M108Example macro in Klipper's sample configurationBuilt in; parks at X 211, Y 0 and lifts 2 mmBuilt 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:

  1. Start from the code your slicer ships for your printer, not a snippet for another machine.

  2. 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.

  3. Change one thing at a time and comment each line you touch.

  4. Try a single command first from a host terminal, such as OctoPrint's Terminal tab.

  5. 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.

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.