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.

1 Answer 1



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

old answer

  1. Set scrolloff to 5

    vim.opt.scrolloff = 5
  2. Set keymap M to zt.

    vim.api.nvim_set_keymap('n', 'M', 'zt', NOREF_NOERR_TRUNC)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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