Can I put Globals: in an external file?

I have a bunch of globals:

globals:
  - id: line1x
    type: int
    initial_value: '0'
  - id: line1y
    type: int
    initial_value: '0'

  - id: line2x
    type: int
    initial_value: '0'
  - id: line2y
    type: int
    initial_value: '50'

… that are cluttering up my view of the program. Can I cut 'n paste them into an external file?
Leaning on my Arduino IDE past, I would use the #include directive.

Regards, Martin

And indeed you can use the !include directive in your ESPHome YAML. It’s documented in the HA docs.

Not going too well… Thought it would be straight-forward. But no!
This is the head of my yaml file:

esphome:
  name: esp32s2-msp2807
  friendly_name: "ESP32 S2 msp2807"
  includes:
    - esp32s2-msp2807.h
    
esp32:
  board: lolin_s2_mini
  framework:
    type: arduino

If I miss-spell the includes: filename, the editor complains. So I guess that that bits right?
And this is esp32s2-msp2807.h (absolute path: /config/esphome/esp32s2-msp2807.h):

globals:
  - id: line1x
    type: int
    initial_value: '0'
  - id: line1y
    type: int
    initial_value: '0'

  - id: line2x
    type: int
    initial_value: '0'
  - id: line2y
    type: int
    initial_value: '50'

… and lastly, this is the section in the project file that references the globals: held in the header file:

display:
  - platform: ili9xxx
#
# truncated for brevity....
#
    lambda: |-
      it.printf(id(line1x), id(line1y), id(my_font), TextAlign::TOP_LEFT, "Temperature");
      it.printf(it.get_width(), id(line1y), id(my_font), TextAlign::TOP_RIGHT, " %.1f°C", id(outside_temp).state);

      it.printf(id(line2x), id(line2y), id(my_font), "Veh.Volts");
      it.printf(it.get_width(), id(line2y), id(my_font), TextAlign::TOP_RIGHT, " %.1fV", id(veh_volts).state);

      it.printf(id(line3x), id(line3y), id(my_font), "Veh.Amps");
      it.printf(it.get_width(), id(line3y), id(my_font), TextAlign::TOP_RIGHT, " %.1fA", id(veh_amps).state);

#
#et cetera....

As is, the HA editor reports that “line1x”, “line2x” can not be found?

You want tomput part of YAML file in another file - includes not the case to do it.
Use packages or <<: !include directive.

I posted the wrong link earlier, but if you want to extract multiple parts of the config, than as @Masterzz says, use packages:.

!include (as opposed to includes: is useful for replacing the value for a single key.