dotfiles/nvim/lua/config/keymaps/indent.lua

30 lines
568 B
Lua
Raw Normal View History

2024-01-26 17:47:29 +01:00
local get_visual = require 'config.helpers.visual'
local M = {}
function M.normalize()
2024-06-13 21:48:16 +02:00
local c = vim.fn.getpos '.'
local s = get_visual()
2024-01-26 17:47:29 +01:00
2024-06-13 21:48:16 +02:00
local max = 0
for line = s.sr, s.er do
local indent = vim.fn.indent(line)
max = indent > max and indent or max
end
2024-01-26 17:47:29 +01:00
2024-06-13 21:48:16 +02:00
for line = s.sr, s.er do
local content = vim.fn.getline(line)
if content:len() > 0 then
local current = vim.fn.indent(line)
if current ~= max then
local new = string.rep(' ', max - current)
vim.fn.setline(line, new .. content)
end
end
end
2024-01-26 17:47:29 +01:00
2024-06-13 21:48:16 +02:00
vim.fn.setpos('.', c)
2024-01-26 17:47:29 +01:00
end
return M