runtime(defaults): Detect putty terminal and switch to dark background
Commit:
https://github.com/vim/vim/commit/2abec431e1ab5f4f6e21c2bb490241732622a8c5
Author: Christian Brabandt <[email protected]>
Date: Sun Oct 27 21:33:09 2024 +0100
runtime(defaults): Detect putty terminal and switch to dark background
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 <[email protected]>
diff --git a/runtime/defaults.vim b/runtime/defaults.vim
index ff8ce8ea1..459841ffc 100644
--- a/runtime/defaults.vim
+++ b/runtime/defaults.vim
@@ -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 == " [>0;136;0c" | set bg=dark |
endif
augroup END
" Quite a few people accidentally type "q:" instead of ":q" and get confused
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index f200a30e5..6ca00a6e1 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -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 == " [>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
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index af180a223..2a3846669 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -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 ~
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index e1dbc87fe..30ded35b8 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -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("
", 't') " for the hit-enter prompt
set verbose=20
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1t5A8F-00Bs8J-6S%40256bit.org.