     (set-input-stream System/in sys-in)
     (set-output-stream System/out sys-out)
     (set-output-stream System/err sys-err)
-    (.print (.out ctx)
-            (print-str
-              (util/clj->vim
-                {:value  result
-                 :stdout (.toString out encoding)
-                 :stderr (.toString err encoding)})))
+    (let [output (.getBytes
+                   (print-str
+                     (util/clj->vim
+                       {:value  result
+                        :stdout (.toString out encoding)
+                        :stderr (.toString err encoding)}))
+                   encoding)]
+      (.write (.out ctx) output 0 (alength output)))
     (.flush (.out ctx))))
 
 (defmacro defnail

     (.start))))

(defn- make-stream-set
  [in out err]
  [(-> in InputStreamReader. LineNumberingPushbackReader.)
   (-> out OutputStreamWriter.)
   (-> err OutputStreamWriter. PrintWriter.)])

(defn- set-input-stream
  [#^ThreadLocalInputStream sys local]

  [#^NGContext ctx nail]
  (let [out          (ByteArrayOutputStream.)
        err          (ByteArrayOutputStream.)
        encoding     (System/getProperty "clojure.vim.encoding" "UTF-8")
        [clj-in clj-out clj-err] (make-stream-set (.in ctx) out err encoding)
        sys-in       (set-input-stream System/in (.in ctx))
        sys-out      (set-output-stream System/out (PrintStream. out))
        sys-err      (set-output-stream System/err (PrintStream. err))
