Abort wrong statement in iex

If I make a mistake in iex it enters a mode that I don’t know how to get out of. For example:

Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> %Struct{key: “key”, val: "val}

At this point I have no idea how to abort that statement. My only option is Ctrl-C to start over. Is there a way to abort inside iex?

1 Like

Just type an additional " to close the quotation and press return. Depending on the exact typo
you might need to do something like this as well:

iex(2)> %Struct{ key: "key, val: }
...(2)> "
...(2)> }
** (CompileError) iex:2: Struct.__struct__/1 is undefined, cannot expand struct Struct

You will get an error, but you won’t lose your context. Basically, just keep typing the close char for whatever is opened and return until you get an error.

There is likely a better way, but I haven’t found it yet.

#iex:break on a new line will stop the parsing of the current expression. It’s documented in the docs for iex


That’s exactly what I was looking for. Thanks Kronic!