In-code shell and Python eval

Inline shellPython evaluationConfigurationWhy?

Run shell commands and evaluate Python expressions without leaving the editor.

inline-shell-and-python-eval.webp

Commands and their results stay in the document, making it easy to keep calculations, output, and notes together.

Inline shell

Start a line with % to run it as a shell command:

% pwd

Place the cursor on the line and run Inline Command:

Action Result
⌘ Command + ⇧ Shift + Return Run the current line as an inline command.

Koi runs the command and inserts its output on the following line:

% pwd
/Users/michael/project

The % prefix can be changed in the configuration.

Python evaluation

Lines without the shell prefix can be evaluated as Python expressions using the same Inline command.

sum(x * x for x in range(10))
285

This works well for quick calculations and small transformations:

2 ** 16
65536
", ".join(str(x) for x in range(5))
'0, 1, 2, 3, 4'
print(24*"-")
------------------------

The result is inserted directly below the expression.

Configuration

Inline commands can be enabled for specific file types:

inline_command_in_files             txt, md, org,
inline_shell_start_symbol           %

Why?

Small commands and calculations often don't need a separate Terminal or Python REPL.

Run them where you're already working and leave the result in the document when it's useful. This works particularly well for notes, documentation, debugging, quick calculations, and lightweight executable documents.