fix: smart indentation was counting \t as a character.

The code now counts the amount of characters up to a \t, which we know
is already aligned.
This commit is contained in:
2025-12-23 09:56:18 +01:00
parent 8f332f09f8
commit 81614f36bf

View File

@@ -38,14 +38,20 @@ Map('n', 'gr', vim.lsp.buf.references, { desc = "Go to the reference" })
-- smart tabulation
Map('i', '<tab>', function()
local _, col = unpack(vim.api.nvim_win_get_cursor(0)) -- get cursor position
local isindent = vim.api.nvim_get_current_line():sub(1, col):match('^%s*$')
local ln = vim.api.nvim_get_current_line():sub(1, col)
local isindent = ln:match('^%s*$')
local tabexpnd = vim.bo.expandtab
local tabwidth = vim.bo.shiftwidth > 0 and vim.bo.shiftwidth or vim.bo.tabstop
if not tabexpnd and isindent then
return '\t'
else
local spaces = tabwidth - col % tabwidth
else -- Compute the amount of spaces needed for the line.
local i = col
while i >= 1 do
if ln:sub(i, i) == '\t' then break end
i = i - 1
end
local spaces = tabwidth - (col - i) % tabwidth
return string.rep(' ', spaces == 0 and tabwidth or spaces)
end
end, { expr = true, desc = "smart tabulation" })