go to last loc when opening a buffer

This commit is contained in:
Enrique MP 2023-10-08 20:10:24 +02:00
parent 65ac1d0823
commit ce49a449d1

View file

@ -29,3 +29,21 @@ au({ "BufRead", "BufNewFile" }, {
vim.opt_local.spelllang = "en,es"
end,
})
-- go to last loc when opening a buffer
local LastLoc = ag("last_loc", { clear = true })
au("BufReadPost", {
group = LastLoc,
callback = function(event)
local exclude = { "gitcommit" }
local buf = event.buf
if vim.tbl_contains(exclude, vim.bo[buf].filetype) then
return
end
local mark = vim.api.nvim_buf_get_mark(buf, '"')
local lcount = vim.api.nvim_buf_line_count(buf)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
})