1

I've just noticed that if the cursor is at the last line of a file and I enter insert mode, then the buffer pans so that the cursorline is at the bottom of the [sub]window, as if in response to a zb command, before entering insert mode.

I later found that any cursor movement (e.g., [) also causes the last line of the file to pan down to the bottom of the window.

Is there a setting responsible for this? I would like to disable this new behaviour.

Work-arounds tried

I tried to save all the information on my buffers using :mksession! ~/session.x.vim and restarting things using gvim -S ~/session.x.vim, but the behaviour persisted into the new session.

If one has the BufExplorer plugin, it is possible to avoid the unwanted behaviour by starting a new Gvim session without sourcing the mksession file from the old session, then recover some of the context from the old session. In the old session, you have to write the list of buffers and their folder paths into (say) ~/tmp/tmp.txt, then abandon the old session and start a new gvim session without sourcing ~/session.x.vim. The unwanted behaviour does not persist into such a new session.

To recover the context of the old session, one can use the file names and folder paths in ~/tmp/tmp.txt and a few regular expression search-and-replacements to reconstruct the list of full paths to each file. It is then simple to visit each file in the list using command gf, thereby rebuilding the buffer list.

To avoid this in the future, I'd be curious whether there is a setting that caused the automatic panning of the last line of the file to the bottom of the screen.

Annex: Vim version:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jul  7 2023 22:50:38)
Included patches: 1-4372
Modified by <[email protected]>
Compiled by <[email protected]>
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
+balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
+browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     +perl/dyn          +title
+channel           +ipv6              +persistent_undo   +toolbar
+cindent           +job               +popupwin          +user_commands
+clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby/dyn          +wildignore
+cursorbind        +lua/dyn           +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con_gui    +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            +X11
+digraphs          +mouse             +sound             -xfontset
+dnd               +mouseshape        +spell             +xim
-ebcdic            +mouse_dec         +startuptime       +xpm
+emacs_tags        -mouse_gpm         +statusline        +xsmp_interact
+eval              -mouse_jsbterm     -sun_workshop      +xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary        
-farsi             -mouse_sysmouse    -tag_old_static    
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"

Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK
-I/usr/include/gtk-3.0 -I/usr/include/pango-1.0
-I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo
-I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include
-I/usr/include/atk-1.0 -I/usr/include/freetype2
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-I/usr/include/at-spi2-atk/2.0 -I/usr/include/libpng16
-I/usr/include/at-spi-2.0 -I/usr/include/pixman-1
-I/usr/include/harfbuzz -I/usr/include/gio-unix-2.0/ -D_REENTRANT
-I/usr/include/uuid -ggdb -O2 -pipe -Wall -Werror=format-security
-fstack-protector-strong --param=ssp-buffer-size=4
-fdebug-prefix-map=/pub/devel/vim/vim-8.2.4372-2.x86_64/build=/usr/src/debug/vim-8.2.4372-2
-fdebug-prefix-map=/pub/devel/vim/vim-8.2.4372-2.x86_64/src/vim-8.2.4372=/usr/src/debug/vim-8.2.4372-2
-fstack-protector-strong -DSYS_VIMRC_FILE=/etc/vimrc -D_REENTRANT
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 

Linking: gcc -L. -fstack-protector-strong -Wl,--no-as-needed
-L/usr/local/lib -Wl,--as-needed -o vim.exe -lgtk-3 -lgdk-3 -latk-1.0
-lgio-2.0 -lpangocairo-1.0 -lcairo-gobject -lpango-1.0
-lgdk_pixbuf-2.0 -lcairo -lglib-2.0 -lintl -lgobject-2.0 -lSM -lICE
-lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -lelf -lncursesw -lcanberra
-lsodium -liconv -lacl -lattr -lintl -Wl,--enable-auto-import
-Wl,--export-all-symbols -Wl,--enable-auto-image-base
-fstack-protector-strong
-L/usr/lib/perl5/5.36/x86_64-cygwin-threads/CORE -lperl -lpthread -ldl
-lcrypt 
9
  • does it happen with --clean? Sep 5, 2023 at 6:03
  • "Is there a setting responsible for this? I would like to disable this new behaviour." What you describe is not the expected behavior so it is certainly caused by something you added to your config… which we have no access to.
    – romainl
    Sep 5, 2023 at 6:04
  • @Christian Brabandt: Unfortunately, I can't reproduce it at will. I assumed it is due to some inadvertent buttonology on my part, so I'm trying to find out what it is. Not only so that I can try to avoid it, but also in case it is reversible without nuking the Vim session. Sep 5, 2023 at 6:10
  • I'm unable to reproduce this behaviour in vim 8.1 (under a clean setup vim -u NONE and gvim -u NONE). While cursor is at the last line, I press zz, enter insert mode with i, and no repositioning happens.
    – Hoblovski
    Sep 5, 2023 at 11:27
  • That's not surprising, I've never seen this behaviour before and I've used Vim for decades. I was hoping that I could identify the things/settings that trigger this behaviour so that it can be avoided or reversed. Sep 5, 2023 at 14:28

1 Answer 1

2

The cause of the problem is :set scrolloff=9999, which one might use during searches to keep the cursor line as the middle row of the [sub]window. From the help documentation, this is expected behaviour.

Thanks to the D. Ben Knoble for persistence in reminding me of troubleshooting possibilities.

On that note, my strategy wasn't to use methods for troubleshooting vimrc, since I was troubleshooting the mksession file from the old ("bad") session. It didn't source any external files, so higher level strategies didn't seem applicable, e.g., selectively enabling/disabling plugins.

Instead, the approach taken was to comment out each half of the session file commands to see which half the problem resided in, then comment out each half of the remaining lines to narrow it down, then repeat this process until the responsible command was obvious.

This does generate error messages because not all commands in the session file make sense when some of preceding commands are commented out or removed. In this case, however, the approach worked in identifying the reponsible command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.