I couldn’t figure it out so I just coded my own and mapped it to shift+tab.
function insert_mode_unindent()
local pos = vim.fn.getpos('.')
pos = pos[3]
local line = vim.api.nvim_get_current_line()
-- If expandtab is false this will also delete \t
if string.sub(line, pos - 1, pos - 1) ~= ' ' then
local s = vim.api.nvim_replace_termcodes('<BS>', true, false, true)
vim.api.nvim_feedkeys(s, 'nt', false)
return
end
-- Calculate indent offset
local width = vim.fn.shiftwidth()
local offset = math.fmod(pos - 1, width)
if offset == 0 then
offset = width
end
-- Delete up to offset amount of space characters
for i = 1, offset do
if string.sub(line, pos - i, pos - i) == ' ' then
-- <BS> can delete more than one character depending on various
-- tab settings so we use <Del> instead
local s = vim.api.nvim_replace_termcodes('<Left><Del>', true, false, true)
vim.api.nvim_feedkeys(s, 'nt', false)
else
break
end
end
end
vim.keymap.set('i', '<S-Tab>', insert_mode_unindent, {noremap = true, silent = true})