summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-06-15 19:16:07 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-06-15 19:16:07 +0900
commitb10343cdb8f33b169700d6a5d5260751a825f8ac (patch)
treef97aac9450c22f5ab22ea654ee7092070bb4470b
parentd8da09ebe46222f73e6ec03b5d06572893d5a161 (diff)
modified core/autocmds.lua
-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,
})