RSSAmplifier

adamu.jp · Dec 4, 2025

Useful shortcuts in iex

0
Sign in to vote or save

adamu.jp

Note: This post is Day 5 of the Qiita Elixir Advent Calendar 2025, so is written in Japanese first. The English version is below.

この投稿はQiita Elixir Advent Calendar 2025の5日目です。よろしくお願いします。

iexを使う時に、こちらのショートカットを使うと、日常的な操作がより楽になると思います。

一番知っておきたいこと:編集中の式を取り消すことができる

複数行の式を入力中に、入力ミスをしてしまい、書き直すためにわざとエラーを起こそうとして必死にキーを叩き続けたことはありませんか?

iex(1)> Enum.map([1,2,3], fn -> "String.trim_leader(
        )
        ]
        )
        ])!
        """\
        "
        }
        """"""
** (SyntaxError) invalid syntax found on iex:11:5:

その必要はありません。

Esc + C を活用しましょう!

Esc + Cを入力すると、入力中の式が全部消えます。便利です。

Before:

iex(1)> :hello
:hello
iex(2)> Enum.map([1,2,3], fn i ->
...(2)> String.pad_leading("#{
...(2)>  ここでEsc + Cを押す

After:

iex(1)> :hello
:hello
iex(2)>

このように入力中の式が消えました 😌

ちなみに、Alt + C でも使えるはずですが、僕はMacを使っていて、Macの場合はOpt+Cçになるので、MacならEscが確実なやり方です。

プロンプト内でカーソルを動かす

  • Ctrl + A 行の先頭に移動する
  • Ctrl + E 行の末尾に移動する
  • Alt + 1語分戻す
  • Alt + 1語分進める

例えば、次のように書いた場合

iex(1)> Enu.map([1,2,3, fn ->

2つの誤りがあります

  • Enumのスペルミス
  • ] の入力ミス

以下の流れで修正していきます

  • Ctrl + A 行の先頭に移動する
  • Alt + 1語分進める
  • m を押してEnumの綴りを直す

そして

  • Alt + 4回、リストの末尾へ移動する
  • ] リストを閉じる

エディターで編集する

正直、この機能はあまり使ったことがないですが、今後使ってみたいと思っています 😁

この機能を活用するには、EDITORVISUAL の環境変数の設定が必要です。事前に用意しておきましょう。

Esc + oを押すと、今入力中の式がテキストエディタで開きます。 好きなように編集して保存すると、更新されたコードが iex に反映されます 😲

この機能は複雑な編集、エディターにコピペしようと思っている時に、役に立ちそうですね。

その他にもたくさんあります

iex は Erlang の tty パッケージを使用しており、tty のドキュメントで使えるショートカット全て記載されていますので、より詳しく知りたい方はぜひ読んでみてください。

(下記、英語版です)


Use iex? I find these shortcuts will help me be more efficient and productive, and make my daily experience more enjoyable.

The best one: cancel current expression

Have you ever been entering a multiple line command, made a typo, and been stuck mashing keys trying to cause a syntax error so you can get back to the prompt?

iex(1)> Enum.map([1,2,3], fn -> "String.trim_leader(
        )
        ]
        )
        ])!
        """\
        "
        }
        """"""
** (SyntaxError) invalid syntax found on iex:11:5:

This is not necessary!

Solution: Esc + C

This will clear the current command as if we never typed anything, ready to start again:

Before:

iex(1)> :hello
:hello
iex(2)> Enum.map([1,2,3], fn i ->
...(2)> String.pad_leading("#{
...(2)>  Esc + C here

After:

iex(1)> :hello
:hello
iex(2)>

The expression was cleared 😌

Note: I beleive Alt + C should also work, but I'm using a Mac, and doing Opt+C results in the ç character. So for Macs, Esc is the most universal way to do this.

Moving around

  • Ctrl + A to go to the start of the line
  • Ctrl + E to go to the start of the line
  • Alt + to go back a word
  • Alt + to go forward a word

For example, if we have written this:

iex(1)> Enu.map([1,2,3, fn ->

We've made two errors:

  • A typo in Enum
  • Forgot the ] bracket.

We can do this:

  • Ctrl + A to get to the beginning of the line
  • Alt + E to get to the end of the word
  • m to fix the typo

Then:

  • Alt + x 4 to get to the end of the list and
  • ] to fix close the list

Edit in editor

I have to admit I've not used this much myself, but after writing this post I'll keep it in mind for the future :D

For this to work you need to have set the EDITOR or VISUAL environment variable.

Esc + o will open the current expression in your text editor. You can edit it as you like, save it, and the updated code will be shown in iex 😲

Pretty nifty

Plenty more

iex uses the tty package from Erlang, which documents the full range of supported shortcuts. Check out the tty docs if you're interested in expanding your CLI repertoire.

Read the original on adamu.jp

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.