lua < 1 then return end local last_line = vim.fn.line([['"]]) local buff_last_line = vim.fn.line("$") -- If the last line is set and the less than the last line in the buffer if last_line > 0 and last_line <= buff_last_line then local win_last_line = vim.fn.line("w$") local win_first_line = vim.fn.line("w0") -- Check if the last line of the buffer is the same as the win if win_last_line == buff_last_line then -- Set line to last line edited vim.cmd.normal{[[g`"]], bang = true} -- Try to center elseif buff_last_line - last_line > ((win_last_line - win_first_line) / 2) - 1 then vim.cmd.normal{[[g`"zz]], bang = true} else vim.cmd.normal{[[G'"]], bang = true} end end end vim.api.nvim_create_autocmd({'BufWinEnter', 'FileType'}, { group = vim.api.nvim_create_augroup('nvim-lastplace', { clear = true }), callback = run }) EOF