- Press ESC to enter normal mode,
- Optional: Type :w (colon + w) to save changes,
- Type :q (colon + q) to exit vi(m).
- If you don’t want to save changes, add an exclamation mark – :q!
More about vi(m) modes you can find e.g. here: https://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/Modes
Telnet is giving you a hint:
Escape character is '^]'
In this case ^ character means control (command in macOs). So combination what you’re looking for is ctrl+].
Then, after entering command mode – type quit (and confirm with enter key).
Simply: type exit.
Exit running script/command
Hit ctrl+c to break/exit from it.
Exit any process
In bash type kill <process ID>
You can also use (h)top app to find process and terminate it.