jszakmeister / vim-togglecursor

Toggle the cursor shape in the terminal for Vim.
http://www.vim.org/scripts/script.php?script_id=4403
119 stars 20 forks source link

Overwrites existing values of t_SI, t_EI #46

Open jfgoodall opened 3 years ago

jfgoodall commented 3 years ago

vim-togglecursor overwites t_SI and t_EI preventing other settings from being applied (i.e. as shown in https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode).

Patch to allow additional, external settings to be supplied as option variables:

From 41e441f9d9305448b5cf48421f6b5b723b287a26 Mon Sep 17 00:00:00 2001
From: James Goodall
Date: Fri, 6 Aug 2021 13:58:47 -0700
Subject: [PATCH] Allow existing values of t_SI, t_EI to be preserved

---
 plugin/togglecursor.vim | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/plugin/togglecursor.vim b/plugin/togglecursor.vim
index 07cbdfb..8824642 100644
--- a/plugin/togglecursor.vim
+++ b/plugin/togglecursor.vim
@@ -136,6 +136,14 @@ if !exists("g:togglecursor_disable_tmux")
     let g:togglecursor_disable_tmux = 0
 endif

+if !exists("g:togglecursor_t_SI_external")
+    let g:togglecursor_t_SI_external = ''
+endif
+
+if !exists("g:togglecursor_t_EI_external")
+    let g:togglecursor_t_SI_external = ''
+endif
+
 " -------------------------------------------------------------
 " Functions
 " -------------------------------------------------------------
@@ -173,8 +181,8 @@ function! s:ToggleCursorInit()
         return
     endif

-    let &t_EI = s:GetEscapeCode(g:togglecursor_default)
-    let &t_SI = s:GetEscapeCode(g:togglecursor_insert)
+    let &t_EI = s:GetEscapeCode(g:togglecursor_default) . g:togglecursor_t_EI_external
+    let &t_SI = g:togglecursor_t_SI_external . s:GetEscapeCode(g:togglecursor_insert)
     if s:sr_supported
         let &t_SR = s:GetEscapeCode(g:togglecursor_replace)
     endif
@@ -189,10 +197,10 @@ endfunction

 function! s:ToggleCursorByMode()
     if v:insertmode == 'r' || v:insertmode == 'v'
-        let &t_SI = s:GetEscapeCode(g:togglecursor_replace)
+        let &t_SI = g:togglecursor_t_SI_external . s:GetEscapeCode(g:togglecursor_insert)
     else
         " Default to the insert mode cursor.
-        let &t_SI = s:GetEscapeCode(g:togglecursor_insert)
+        let &t_SI = g:togglecursor_t_SI_external . s:GetEscapeCode(g:togglecursor_insert)
     endif
 endfunction

-- 
1.8.3.1
jszakmeister commented 3 years ago

Thank you for filing an issue. I'll have to think on this a bit more... all the terminal handling stuff can be rather tricky.