I'm trying to show / hide horizontal scrollbar conditionally, depending on wrap
option:
- with
wrap
- show horizontal scrollbar - with
nowrap
- hide
Here is what I tried, but for some reason it doesn't work:
set guioptions+=%{&wrap?'b':''}
I'm trying to show / hide horizontal scrollbar conditionally, depending on wrap
option:
wrap
- show horizontal scrollbarnowrap
- hideHere is what I tried, but for some reason it doesn't work:
set guioptions+=%{&wrap?'b':''}
I guess you want the horizontal scrollbar on nowrap
.
You can handle this with a autocmd, like:
autocmd OptionSet wrap if &wrap|set guioptions-=b|else|set guioptions+=b|endif
If you change the option wrap
during runtime, this will automatically switch on/off the horizontal scrollbar. The autocommand is not triggered on startup (sourcing vimrc
), see :help OptionSet
.
In your vimrc, you should define your initial settings like:
set nowrap
...
if &wrap
set guioptions-=b
else
set guioptions+=b
endif
This way, you just need to change wrap
and guioptions
will be changed as needed. Order is important here.
set wrap
(set nowrap
) and this one.
– james
Feb 10 at 10:21
set wrap
, in which case it'll be triggered.
– filbranden
Feb 10 at 16:23
vimrc
. The docs say "Is not triggered on startup...".
– Ralf
Feb 10 at 16:31