I use (neo)vim with mouse=a
and scrolloff=5
. Clicking on one of the top or bottom five lines with the mouse causes the screen to jump (so that the new cursor position is more centered), which distracts me. Is there any way to disable "so=5
" for mouse-clicking only?
Try the following: hold down shift key before you press mouse button.
If you want to avoid test scrolling when you mouse-click at edges of the window, you can simply set scrolloff to 0, see comments in /usr/share/vim/vim80/defaults.vim
(ubuntu 1804):
" Show a few lines of context around the cursor. Note that this makes the
" text scroll if you mouse-click near the start or end of the window.
set scrolloff=5
Note that you have to set scrolloff=0
after sourcing the above defaults.vim
if you are using .vimrc
copied from vimrc_example.vim
, on Ubuntu for example, set it like:
" Get the defaults that most users want.
source $VIMRUNTIME/defaults.vim
set scrolloff=0
-
Hi, welcome! The OP wants to set
scrolloff
to a non-zero value. Thus, I'm not quite sure your answer is relevant. – Biggybi Feb 23 at 12:23
This occurs to me:
nnoremap <leftmouse> :let oldso = &scrolloff <bar> let &scrolloff = 0<CR><leftmouse>:let &scrolloff = oldso <bar> unlet oldso<CR>
Save the old value, set to 0; do the mouse click; restore the value.
-
This seems to produce identical results to regular
<leftmouse>
. Am I missing something? – 0x539 Mar 25 at 19:50 -
I see the problem @0x539 : because
scrolloff
is restored immediately afterwards, there is still a jump. You could leave off the restore and define another mapping/command to restore (e.g.,command RestoreScroll let &scrolloff = oldso | unlet oldso
), but you would have to call it yourself when you wanted it. – D. Ben Knoble♦ Mar 25 at 19:53
scrolloff
set a minimal number of lines below or above the cursor line. Disabling the option "only for mouse click" would mean that you don't have this minimal number of lines between the cursor line and the edge of the screen but how would vim know when to set this minimal number of lines again? – statox Apr 7 '19 at 17:25nnoremap <leftmouse> :set scrolloff=0<CR><leftmouse>
to disablescrolloff
when you click and then remap the motion you want to reenable the option but that seems very impractical. – statox Apr 7 '19 at 17:29