diff --git a/tests/cmdline/repl_cont.py b/tests/cmdline/repl_cont.py
index 66a484ce3d4b4fe1979a486e16e9887ea83b6eac..06c445d1288bd71a06ec77b4f5e61db9cef046ac 100644
--- a/tests/cmdline/repl_cont.py
+++ b/tests/cmdline/repl_cont.py
@@ -16,6 +16,6 @@ d = {1:'one',
 2:'two'}
 print(d[2])
 def f(x):
- print(x)
-
+print(x)
+
 f(3)
diff --git a/tests/cmdline/repl_cont.py.exp b/tests/cmdline/repl_cont.py.exp
index 927a237c5fca7b0c392afabf3fcce4d1b7ce7905..1f8f9f5faccfb39a8f368e4e6aba6a9c81f5b8bb 100644
--- a/tests/cmdline/repl_cont.py.exp
+++ b/tests/cmdline/repl_cont.py.exp
@@ -25,8 +25,8 @@ Micro Python \.\+ version
 >>> print(d[2])
 two
 >>> def f(x):
-...  print(x)
-... 
+...     print(x)
+...     
 >>> f(3)
 3
 >>> 
diff --git a/unix/main.c b/unix/main.c
index aede75353b40e8aa29a8e457a6ad01dde5f406f1..651c3836cc96d5612b346f58cc9df84fa7d6cc27 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -134,6 +134,9 @@ STATIC int execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind,
     }
 }
 
+#if MICROPY_USE_READLINE == 1
+#include "lib/mp-readline/readline.h"
+#else
 STATIC char *strjoin(const char *s1, int sep_char, const char *s2) {
     int l1 = strlen(s1);
     int l2 = strlen(s2);
@@ -147,10 +150,63 @@ STATIC char *strjoin(const char *s1, int sep_char, const char *s2) {
     s[l1 + l2] = 0;
     return s;
 }
+#endif
 
 STATIC int do_repl(void) {
     mp_hal_stdout_tx_str("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_PY_SYS_PLATFORM " version\n");
 
+    #if MICROPY_USE_READLINE == 1
+
+    // use MicroPython supplied readline
+
+    vstr_t line;
+    vstr_init(&line, 16);
+    for (;;) {
+    input_restart:
+        vstr_reset(&line);
+        mp_hal_stdio_mode_raw();
+        int ret = readline(&line, ">>> ");
+
+        if (ret == CHAR_CTRL_D) {
+            // EOF
+            printf("\n");
+            mp_hal_stdio_mode_orig();
+            vstr_clear(&line);
+            return 0;
+        } else if (line.len == 0) {
+            if (ret != 0) {
+                printf("\n");
+            }
+            mp_hal_stdio_mode_orig();
+            continue;
+        }
+
+        while (mp_repl_continue_with_input(vstr_null_terminated_str(&line))) {
+            vstr_add_byte(&line, '\n');
+            ret = readline(&line, "... ");
+            if (ret == CHAR_CTRL_C) {
+                // cancel everything
+                printf("\n");
+                mp_hal_stdio_mode_orig();
+                goto input_restart;
+            } else if (ret == CHAR_CTRL_D) {
+                // stop entering compound statement
+                break;
+            }
+        }
+        mp_hal_stdio_mode_orig();
+
+        mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, line.buf, line.len, false);
+        ret = execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, true);
+        if (ret & FORCED_EXIT) {
+            return ret;
+        }
+    }
+
+    #else
+
+    // use GNU or simple readline
+
     for (;;) {
         char *line = prompt(">>> ");
         if (line == NULL) {
@@ -175,6 +231,8 @@ STATIC int do_repl(void) {
         }
         free(line);
     }
+
+    #endif
 }
 
 STATIC int do_file(const char *file) {
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index d503aea97522fe2702f4b7c673ba2ea377fac9a5..f51d1aeae030ceb309d1c37ec2ed50d79b61b079 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -53,6 +53,7 @@
 #define MICROPY_USE_READLINE_HISTORY (1)
 #define MICROPY_HELPER_REPL         (1)
 #define MICROPY_REPL_EMACS_KEYS     (1)
+#define MICROPY_REPL_AUTO_INDENT    (1)
 #define MICROPY_HELPER_LEXER_UNIX   (1)
 #define MICROPY_ENABLE_SOURCE_LINE  (1)
 #define MICROPY_FLOAT_IMPL          (MICROPY_FLOAT_IMPL_DOUBLE)