Allow `zt` and `zb` to temporarily surpress `scrolloff` option
Describe the bug
scrolloff is set to 10 lines.
This disallows zt and zb from hitting true top and bottom.
To Reproduce
In Normal, type the command zt or zb.
Note that top and bottom are impacted by the default scrolloff value.
Desktop
- OS: macOS
- Terminal: Alacritty
Neovim Version
NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1724232689
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.10.1/share/nvim"
Suggestion
Temporarily set scrolloff to zero, only for mapped commands (zt, zb).
-- Custom function to execute a command with temporary scrolloff=0
local function with_scrolloff_0(cmd)
return function()
local scrolloff = vim.o.scrolloff
vim.o.scrolloff = 0
vim.cmd('normal! ' .. cmd)
vim.o.scrolloff = scrolloff
end
end
-- Set up custom mappings for zt and zb
vim.keymap.set('n', 'zt', with_scrolloff_0 'zt', { noremap = true, silent = true })
vim.keymap.set('n', 'zb', with_scrolloff_0 'zb', { noremap = true, silent = true })
dang. realizing this also only works momentarily. any new motions will add the scrolloff back.
interested in other possible solutions.
Try just this.
vim.keymap.set('n', 'zt', ':let save_scrolloff = &scrolloff<CR>:set scrolloff=0<CR>zt:let &scrolloff = save_scrolloff<CR>')
vim.keymap.set('n', 'zb', ':let save_scrolloff = &scrolloff<CR>:set scrolloff=0<CR>zb:let &scrolloff = save_scrolloff<CR>')
this is the same thing without a shared function, right?
It works for me, at least. Can reach true top and bottom. Of course, any subsequent motions will factor in the scrolloff value once the keymap is finished. I'd suggest just removing the scrolloff value entirely if it impedes with your desired workflow, or have a separate keymap that toggles it on/off.
No action items here? Looks like a work around has been offered. Closing. Please re-open if you feel there's actual work for us to do.