]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/nvim/lua/config/autocommands.lua
neovim: configure, using ghostty and tmux
[julm/julm-nix.git] / home-manager / profiles / nvim / lua / config / autocommands.lua
1 local autocmd = vim.api.nvim_create_autocmd
2
3 -- Returns a "clear = true" augroup
4 local function augroup(name)
5 return vim.api.nvim_create_augroup(name, { clear = true })
6 end
7
8 autocmd("BufReadPost", {
9 desc = "Restore cursor position on file reopen, excluding some filetypes",
10 group = augroup("RestoreCursorPosition"),
11 callback = function()
12 local exclude = { "gitcommit" }
13 local buf = vim.api.nvim_get_current_buf()
14 if vim.tbl_contains(exclude, vim.bo[buf].filetype) then
15 return
16 end
17
18 local mark = vim.api.nvim_buf_get_mark(buf, '"')
19 local line_count = vim.api.nvim_buf_line_count(buf)
20 if mark[1] > 0 and mark[1] <= line_count then
21 pcall(vim.api.nvim_win_set_cursor, 0, mark)
22 vim.api.nvim_feedkeys("zvzz", "n", true)
23 end
24 end,
25 })