Skip to content

Commit

Permalink
Merge pull request #53 from joshuachp/feature/last-pos
Browse files Browse the repository at this point in the history
feat(autocmds): remember last position when opening a file
  • Loading branch information
joshuachp authored Feb 7, 2024
2 parents 5cad5d8 + b3cef9c commit cec17f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lua/user-config/autocmds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- Configure autocommands
local M = {}

--- Module entry point
function M.setup()
local augroup = vim.api.nvim_create_augroup('UserConfig', { clear = true })

-- Remember last file position
vim.api.nvim_create_autocmd('BufReadPost', {
group = augroup,
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
if mark[1] > 1 and mark[1] <= vim.api.nvim_buf_line_count(0) then
vim.api.nvim_win_set_cursor(0, mark)
end
end,
})
end

return M
1 change: 1 addition & 0 deletions lua/user-config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local M = {}
--- Setup Lua config
function M.setup()
-- Packages configuration
require('user-config.autocmds').setup()
require('user-config.plugins').setup()
require('user-config.tree-sitter').setup()
require('user-config.diagnostic').setup()
Expand Down

0 comments on commit cec17f3

Please sign in to comment.