As title. Since no one wants to become a turtle, I want to setup a behavior like M
but instead pin the current line to 80% height (0% start from bottom) of the current window, not to center.
-
1M doesn’t center lines; it goes to the middle line. Do you perhaps mean zz, zt, etc.?– D. Ben Knoble ♦Commented May 27, 2022 at 14:20
Add a comment
|
2 Answers
:h H
accepts a count, so you can do something like this:
exe "normal " .. winheight(0) * 80 / 100 .. "H"
which translates to XH
where X
is a number.
Update
Since I don't like scrolloff, I update to this new version:
vim.api.nvim_set_keymap('n', 'M', '<cmd>lua pin_to_80_percent_height()<CR>', NOREF_NOERR_TRUNC)
function _G.pin_to_80_percent_height()
vim.opt.scrolloff = 5
vim.cmd("exe 'normal! zt'")
vim.opt.scrolloff = 0
end
old answer
Set
scrolloff
to5
vim.opt.scrolloff = 5
Set keymap
M
tozt
.vim.api.nvim_set_keymap('n', 'M', 'zt', NOREF_NOERR_TRUNC)