]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(defaults): Detect putty terminal and switch to dark background
authorChristian Brabandt <cb@256bit.org>
Sun, 27 Oct 2024 20:33:09 +0000 (21:33 +0100)
committerChristian Brabandt <cb@256bit.org>
Sun, 27 Oct 2024 20:36:09 +0000 (21:36 +0100)
Vim tries to determine the default background and checks for $TERM
and even checks for the "putty" value. But unfortunately, putty by
default uses "xterm" as $TERM value and as such Vim uses a "light"
background.

So use a TermResponse autocommand to set the background for putty back
to dark.

Note: this only works on non-tiny builds and when defaults.vim is in
use.

Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/defaults.vim
runtime/doc/autocmd.txt
runtime/doc/version9.txt
src/testdir/test_cmdline.vim

index ff8ce8ea18f3fe34843757ecc3b284a2b4053d8f..459841ffcc93747e210842fc4c91b148ad0528d0 100644 (file)
@@ -115,6 +115,11 @@ if 1
       \ |   execute "normal! g`\""
       \ | endif
 
+    " Set the default background for putty to dark. Putty usually sets the 
+    " $TERM to xterm and by default it starts with a dark background which
+    " makes syntax highlighting often hard to read with bg=light
+    " undo this using:  ":au! vimStartup TermResponse"
+    autocmd TermResponse * if v:termresponse == "\e[>0;136;0c" | set bg=dark | endif
   augroup END
 
   " Quite a few people accidentally type "q:" instead of ":q" and get confused
index f200a30e5025bdd58daf000e92eb6ab967c824b1..6ca00a6e1efa4cb289ffe68aca497139875e689c 100644 (file)
@@ -1,4 +1,4 @@
-*autocmd.txt*   For Vim version 9.1.  Last change: 2024 Aug 18
+*autocmd.txt*   For Vim version 9.1.  Last change: 2024 Oct 27
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1254,10 +1254,19 @@ TerminalWinOpen                 Just after a terminal buffer was created, with
 TermResponse                   After the response to |t_RV| is received from
                                the terminal.  The value of |v:termresponse|
                                can be used to do things depending on the
-                               terminal version.  Note that this event may be
-                               triggered halfway executing another event,
-                               especially if file I/O, a shell command or
-                               anything else that takes time is involved.
+                               terminal version.
+                               This is used in |defaults.vim| to detect
+                               putty terminal and set a dark background: >
+
+                               au TermResponse *
+                               \ if v:termresponse == "\e[>0;136;0c"
+                               \    set bg=dark
+                               \ endif
+<
+                               Note: that this event may be triggered halfway
+                               executing another event, especially if file
+                               I/O, a shell command or anything else that
+                               takes time is involved.
                                                        *TermResponseAll*
 TermResponseAll                        After the response to |t_RV|, |t_RC|, |t_RS|,
                                |t_RB|, |t_RF|, or |t_u7| are received from
index af180a2238f5704efeb4016f7c13b58f2a81375c..2a3846669d9d879dd58e208d384664f971a5140b 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2024 Oct 22
+*version9.txt*  For Vim version 9.1.  Last change: 2024 Oct 27
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41600,6 +41600,8 @@ Changed~
 - |:keeppatterns| preserves the last substitute pattern when used with |:s|
 - |setqflist()| and |setloclist()| can optionally try to preserve the current
   selection in the quickfix list with the "u" action.
+- the putty terminal is detected using an |TermResponse| autocommand in
+  |defaults.vim| and Vim switches to a dark background
 
                                                        *added-9.2*
 Added ~
index e1dbc87fe22950447db69bd3290e7fb33efdaaea..30ded35b8d90f3e8d6060a049c6cdb947a3d87d7 100644 (file)
@@ -1701,6 +1701,8 @@ func Test_verbose_option()
   CheckScreendump
 
   let lines =<< trim [SCRIPT]
+    " clear the TermResponse autocommand from defaults.vim
+    au! vimStartup TermResponse
     command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
     call feedkeys("\r", 't') " for the hit-enter prompt
     set verbose=20