summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/core/autocmds.lua8
1 files changed, 7 insertions, 1 deletions
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/core/autocmds.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/core/autocmds.lua
index a62695b..b981a3c 100644
--- a/ar/.config/TheSiahxyz/lua/thesiahxyz/core/autocmds.lua
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/core/autocmds.lua
@@ -137,7 +137,13 @@ autocmd("BufWritePre", {
local cursor_pos = vim.api.nvim_win_get_cursor(0)
vim.cmd([[ %s/\s\+$//e ]]) -- Remove trailing spaces
vim.cmd([[ %s/\n\+\%$//e ]]) -- Remove trailing newlines
- vim.api.nvim_win_set_cursor(0, cursor_pos)
+ local line_count = vim.api.nvim_buf_line_count(0)
+ local line = math.min(cursor_pos[1], line_count)
+ local col = cursor_pos[2]
+ -- Optional: clamp column if line got shorter
+ local line_text = vim.api.nvim_buf_get_lines(0, line - 1, line, false)[1] or ""
+ col = math.min(col, #line_text)
+ vim.api.nvim_win_set_cursor(0, { line, col })
end,
})