From 150e23a42f6d68d17f2582c6975bfa6e8ebc7a4a Mon Sep 17 00:00:00 2001
From: Robert Cranston <rcrnstn@rcrnstn.net>
Date: Tue, 14 Nov 2017 23:36:30 +0100
Subject: [PATCH 2/2] Disable interception of escape codes during macro in
 Insert mode

---
 plugin/rsi.vim | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/plugin/rsi.vim b/plugin/rsi.vim
index 14969ab..b03e23f 100644
--- a/plugin/rsi.vim
+++ b/plugin/rsi.vim
@@ -46,13 +46,27 @@ if &encoding ==# 'latin1' && has('gui_running') && !empty(findfile('plugin/sensi
 endif
 
 if !has("gui_running") && !has('nvim')
-  silent! exe "set <S-Left>=\<Esc>b"
-  silent! exe "set <S-Right>=\<Esc>f"
-  silent! exe "set <F31>=\<Esc>d"
-  silent! exe "set <F32>=\<Esc>n"
-  silent! exe "set <F33>=\<Esc>p"
-  silent! exe "set <F34>=\<Esc>\<C-?>"
-  silent! exe "set <F35>=\<Esc>\<C-H>"
+  augroup rsi_meta_terminal
+    autocmd!
+    autocmd BufWinEnter,InsertLeave,CursorHoldI *
+    \ silent! exe "set <S-Left>=\<Esc>b"
+    \ silent! exe "set <S-Right>=\<Esc>f"
+    \ silent! exe "set <F31>=\<Esc>d"
+    \ silent! exe "set <F32>=\<Esc>n"
+    \ silent! exe "set <F33>=\<Esc>p"
+    \ silent! exe "set <F34>=\<Esc>\<C-?>"
+    \ silent! exe "set <F35>=\<Esc>\<C-H>"
+    autocmd InsertEnter *
+    \ silent! exe "set <S-Left>="
+    \ silent! exe "set <S-Right>="
+    \ silent! exe "set <F31>="
+    \ silent! exe "set <F32>="
+    \ silent! exe "set <F33>="
+    \ silent! exe "set <F34>="
+    \ silent! exe "set <F35>="
+    autocmd InsertEnter * let s:updatetime_old = &updatetime | let &updatetime = 0
+    autocmd InsertLeave * let &updatetime = s:updatetime_old
+  augroup END
   noremap!        <F31> <C-O>dw
   cnoremap        <F31> <S-Right><C-W>
   noremap!        <F32> <Down>
-- 
2.17.1