Configure IEx for Better Struct Visualization in Elixir
2025-02-01 3 min Elixir
Want to make your Elixir structs more readable in IEx? Here’s how
IEx.configure(
inspect: [
pretty: true,
limit: :infinity,
structs: false,
width: 80,
printable_limit: 50
]
)
Before
%User{
bio: "Passionate Elixir developer with 3+ years of experience... (500+ characters)",
email: "[email protected]",
id: 12345,
last_login: ~U[2024-05-25 14:22:18Z],
metadata: %{last_active_project: "iex-config-toolkit", project_count: 27},
preferences: %Preferences{...},
registration_date: ~U[2024-01-15 08:30:00Z],
roles: [:admin, :moderator, ...],
...
}
After
%{
__struct__: User,
bio: "Passionate Elixir developer with 3+ years of exper" <> ...,
email: "[email protected]",
id: 12345,
last_login: %{
__struct__: DateTime,
calendar: Calendar.ISO,
day: 25,
hour: 14,
microsecond: {0, 0},
minute: 22,
month: 5,
second: 18,
std_offset: 0,
time_zone: "Etc/UTC",
utc_offset: 0,
year: 2024,
zone_abbr: "UTC"
},
metadata: %{last_active_project: "iex-config-toolkit", project_count: 27},
preferences: %{
__struct__: Preferences,
language: "es",
notifications: %{email: true, push: false},
theme: "dark"
},
registration_date: %{
__struct__: DateTime,
calendar: Calendar.ISO,
day: 15,
hour: 8,
microsecond: {0, 0},
minute: 30,
month: 1,
second: 0,
std_offset: 0,
time_zone: "Etc/UTC",
utc_offset: 0,
year: 2024,
zone_abbr: "UTC"
},
roles: [:admin, :moderator, :contributor],
settings: %{__struct__: Settings, privacy_level: :high, two_factor_auth: true},
username: "johndoe_dev"
}
Key Features
- pretty: true → Multi-line indentation
- limit: :infinity → No element truncation in lists/maps
- width: 80 → Formatting control
Pro Tips
- Save to .iex.exs → Makes configuration persistent
- structs: false → Reveals nested structs as maps
Advanced Options
- printable_limit: 50 → Truncates long strings/binaries at 50 chars
- charlists: :as_lists → Displays charlists as code points [102, 111, 111]
Save this tip for later! 📩