Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable horizontal scrollbar to pop when ‘nowrap’ is set in Vim?

Tags:

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?

like image 401
James bond Avatar asked Jan 25 '12 10:01

James bond


People also ask

How do I scroll sideways in Vim?

You just press z once in order to trigger the "horizontal scrolling mode", which stop as soon as you press any other key.

How do you add a horizontal scroll overflow?

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.

How do I make my element horizontally scrollable?

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.


1 Answers

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+=bEnter

when the wrap option is set (and evaluates to one), or into

:set wrap! go-=bEnter

otherwise (when &wrap evaluates to zero).

like image 53
ib. Avatar answered Oct 12 '22 20:10

ib.