fix(autocmds): better way of opening file at last location

This commit is contained in:
Folke Lemaitre 2023-01-02 17:36:49 +01:00
parent 08e6a880f5
commit 63bea54be2
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -11,7 +11,11 @@ vim.api.nvim_create_autocmd("TextYankPost", {
-- go to last loc when opening a buffer
vim.api.nvim_create_autocmd("BufReadPost", {
callback = function()
vim.cmd([[silent! normal! g`"]])
local mark = vim.api.nvim_buf_get_mark(0, '"')
local lcount = vim.api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
})