Skip to content

Commit 2abec43

Browse files
committed
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 <cb@256bit.org>
1 parent ce35ee8 commit 2abec43

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

runtime/defaults.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ if 1
115115
\ | execute "normal! g`\""
116116
\ | endif
117117

118+
" Set the default background for putty to dark. Putty usually sets the
119+
" $TERM to xterm and by default it starts with a dark background which
120+
" makes syntax highlighting often hard to read with bg=light
121+
" undo this using: ":au! vimStartup TermResponse"
122+
autocmd TermResponse * if v:termresponse == "\e[>0;136;0c" | set bg=dark | endif
118123
augroup END
119124

120125
" Quite a few people accidentally type "q:" instead of ":q" and get confused

runtime/doc/autocmd.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*autocmd.txt* For Vim version 9.1. Last change: 2024 Aug 18
1+
*autocmd.txt* For Vim version 9.1. Last change: 2024 Oct 27
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1254,10 +1254,19 @@ TerminalWinOpen Just after a terminal buffer was created, with
12541254
TermResponse After the response to |t_RV| is received from
12551255
the terminal. The value of |v:termresponse|
12561256
can be used to do things depending on the
1257-
terminal version. Note that this event may be
1258-
triggered halfway executing another event,
1259-
especially if file I/O, a shell command or
1260-
anything else that takes time is involved.
1257+
terminal version.
1258+
This is used in |defaults.vim| to detect
1259+
putty terminal and set a dark background: >
1260+
1261+
au TermResponse *
1262+
\ if v:termresponse == "\e[>0;136;0c"
1263+
\ set bg=dark
1264+
\ endif
1265+
<
1266+
Note: that this event may be triggered halfway
1267+
executing another event, especially if file
1268+
I/O, a shell command or anything else that
1269+
takes time is involved.
12611270
*TermResponseAll*
12621271
TermResponseAll After the response to |t_RV|, |t_RC|, |t_RS|,
12631272
|t_RB|, |t_RF|, or |t_u7| are received from

runtime/doc/version9.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2024 Oct 22
1+
*version9.txt* For Vim version 9.1. Last change: 2024 Oct 27
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41600,6 +41600,8 @@ Changed~
4160041600
- |:keeppatterns| preserves the last substitute pattern when used with |:s|
4160141601
- |setqflist()| and |setloclist()| can optionally try to preserve the current
4160241602
selection in the quickfix list with the "u" action.
41603+
- the putty terminal is detected using an |TermResponse| autocommand in
41604+
|defaults.vim| and Vim switches to a dark background
4160341605

4160441606
*added-9.2*
4160541607
Added ~

src/testdir/test_cmdline.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,8 @@ func Test_verbose_option()
17011701
CheckScreendump
17021702

17031703
let lines =<< trim [SCRIPT]
1704+
" clear the TermResponse autocommand from defaults.vim
1705+
au! vimStartup TermResponse
17041706
command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
17051707
call feedkeys("\r", 't') " for the hit-enter prompt
17061708
set verbose=20

0 commit comments

Comments
 (0)