add intellitab
This commit is contained in:
parent
ce2bb5fb5d
commit
7da9807f23
2 changed files with 51 additions and 49 deletions
|
@ -57,3 +57,5 @@ vim.keymap.set({ "n", "v" }, "<leader>cbf", function()
|
||||||
vim.b[0].disable_autoformat = true
|
vim.b[0].disable_autoformat = true
|
||||||
end
|
end
|
||||||
end, { desc = "Disable autoformat on save buffer" })
|
end, { desc = "Disable autoformat on save buffer" })
|
||||||
|
|
||||||
|
vim.keymap.set("i", "<Tab>", require("scripts.intellitab").indent)
|
||||||
|
|
|
@ -24,8 +24,8 @@ local function indent()
|
||||||
local cursor = v.nvim_win_get_cursor(0)
|
local cursor = v.nvim_win_get_cursor(0)
|
||||||
local line = v.nvim_buf_get_lines(0, cursor[1] - 1, cursor[1], false)[1]
|
local line = v.nvim_buf_get_lines(0, cursor[1] - 1, cursor[1], false)[1]
|
||||||
|
|
||||||
local indentexpr = v.nvim_buf_get_option(0, "indentexpr")
|
local indentexpr = v.nvim_get_option_value("indentexpr", { buf = 0 })
|
||||||
local expand = v.nvim_buf_get_option(0, "expandtab")
|
local expand = v.nvim_get_option_value("expandtab", { buf = 0 })
|
||||||
local shiftwidth = v.nvim_eval("shiftwidth()")
|
local shiftwidth = v.nvim_eval("shiftwidth()")
|
||||||
local tab_char = v.nvim_replace_termcodes("<Tab>", true, true, true)
|
local tab_char = v.nvim_replace_termcodes("<Tab>", true, true, true)
|
||||||
local indent_goal
|
local indent_goal
|
||||||
|
@ -37,7 +37,7 @@ local function indent()
|
||||||
if indent_goal == nil or indent_goal < 0 then
|
if indent_goal == nil or indent_goal < 0 then
|
||||||
if indentexpr ~= "" then
|
if indentexpr ~= "" then
|
||||||
indent_goal = v.nvim_eval(indentexpr)
|
indent_goal = v.nvim_eval(indentexpr)
|
||||||
elseif v.nvim_buf_get_option(0, "cindent") then
|
elseif v.nvim_get_option_value("cindent", { buf = 0 }) then
|
||||||
indent_goal = v.nvim_call_function("cindent", { cursor[1] })
|
indent_goal = v.nvim_call_function("cindent", { cursor[1] })
|
||||||
else
|
else
|
||||||
indent_goal = v.nvim_call_function("indent", { cursor[1] })
|
indent_goal = v.nvim_call_function("indent", { cursor[1] })
|
||||||
|
|
Loading…
Reference in a new issue