Can someone help me to find a solution for the following inconvenience? I would like horizontal scrollbar to appear whenever I set the nowrap
option, and vice versa when I set it back to wrap
.
Currently I use these settings individually to ease my work:
nnoremap <silent> <F3> :if &guioptions=~#'b'<Bar>set guioptions-=b<Bar>else<Bar>set guioptions+=b<Bar>endif<CR> map <F2> :set nowrap! <CR>
Is there a way to toggle them both at the same time, in concordance?
You just press z once in order to trigger the "horizontal scrolling mode", which stop as soon as you press any other key.
To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.
For horizontal scrollable bar use the x and y-axis. Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line.
Let us construct a single command for switching both options accordingly at once. First of all, it should toggle the wrap
option anyway:
:set wrap!
Then, guioptions
should be changed depending on whether wrapping is enabled at the moment of command's execution. If text is wrapped, the bottom scrollbar should be shown in preparation for wrap
to be disabled:
:set guioptions+=b
Alternatively, if text wrapping is turned off, it should hide the bottom scrollbar:
:set guioptions-=b
In order to make one command out of the above three, we can use the expression mapping
:nnoremap <silent><expr> <f2> ':set wrap! go'.'-+'[&wrap]."=b\r"
which turns into the sequence of keystrokes
:set wrap! go+=b
Enter
when the wrap
option is set (and evaluates to one), or into
:set wrap! go-=b
Enter
otherwise (when &wrap
evaluates to zero).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With