local wk = require("which-key") local telescope = require("telescope.builtin") local gitsigns = require("gitsigns") function FormatBufferLines() local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) local formatted_lines = {} for _, line in ipairs(lines) do if #line <= 80 then table.insert(formatted_lines, line) else local words = {} for word in line:gmatch("%S+") do table.insert(words, word) end local current_line = "" for _, word in ipairs(words) do if #current_line + #word + 1 > 80 then table.insert(formatted_lines, current_line) current_line = word else if current_line ~= "" then current_line = current_line .. " " .. word else current_line = word end end end if current_line ~= "" then table.insert(formatted_lines, current_line) end end end vim.api.nvim_buf_set_lines(0, 0, -1, false, formatted_lines) print("Buffer formatted: lines wrapped at 80 characters") end -- local tree = require "nvim-tree.api" function FormatBuffer() -- Save the current cursor position local cursor_position = vim.fn.getpos(".") FormatBufferLines(); -- local command = "fmt" -- -- Run the formatter command on the current buffer -- vim.cmd(":%! " .. command) -- Restore the cursor position vim.fn.setpos(".", cursor_position) -- local current_file = vim.fn.expand("%:p") -- local cmd = string.format("typstyle -i %s", current_file) -- vim.fn.jobstart(cmd, { -- on_exit = function(_, exit_code) -- if exit_code == 0 then -- print("TypestStyle completed successfully") -- -- vim.cmd('edit!') -- Reload the buffer -- vim.fn.setpos(".", cursor_position) -- else -- print("TypestStyle failed with exit code: " .. exit_code) -- end -- end, -- }) end function ToggleTree(source) require("neo-tree.command").execute({ toggle = true, source = source, position = "left", }) end wk.add({ { mode = "n", -- telescope { "ff", function() telescope.find_files() end, desc = "Find file", }, { "fg", function() telescope.live_grep() end, desc = "Live grep", }, { "fb", function() telescope.buffers() end, desc = "List buffers", }, { "fh", function() telescope.help_tags() end, desc = "Help", }, { "fs", function() telescope.lsp_document_symbols() end, desc = "Find symbols", }, { "zz", function() telescope.spell_suggest() end, desc = "Suggest spell", }, { "zr", function() vim.lsp.buf.rename() end, desc = "Rename symbol", }, -- Tests { "tt", function() require("neotest").run.run({ extra_args = { "--", "--nocapture" } }) end, desc = "Test nearest", }, { "tF", function() require("neotest").run.run(vim.fn.expand("%"), { extra_args = { "--", "--nocapture" } }) end, desc = "Test file", }, { "ts", function() require("neotest").summary.toggle() end, desc = "Test summary", }, { "tO", function() require("neotest").output.open({ enter = true }) end, desc = "Test output", }, { "tq", function() require("neotest").run.stop() end, desc = "Test stop", }, { "ft", function() FormatBuffer() end, desc = "Typst fmt", }, -- Centering cursor { "n", "nzzzv", desc = "Center cursor when n (next) during search" }, { "N", "Nzzzv", desc = "Center cursor when n (next) during search" }, -- tab { "", ":BufferLineCycleNext ", desc = "Next tab" }, { "", ":BufferLineCyclePrev", desc = "Previous tab" }, -- Comment { "/", "gcc", desc = "comment toggle", remap = true }, -- Format { "fm", function() require("conform").format({ async = true, lsp_fallback = true }) end, desc = "format files", }, -- nvim-tree -- { "", function() tree.tree.toggle() end, desc = "Toggle file tree" }, { "", function() -- ToggleTree("filesystem") -- require("edgy").toggle("left") require("edgy-group").open_group_offset("left", 1) end, desc = "Toggle left panel", }, { "el", function() require("trouble").open({ mode = "lsp_document_symbols", focus = false, win = { position = "right" }, }) end, }, { "uh", function() require("edgy").toggle("left") end, desc = "left", }, -- Lsp { "K", function() vim.lsp.buf.hover() end, desc = "LSP toggle", }, { "ca", function() vim.lsp.buf.code_action() end, desc = "LSP code action", }, { "cd", "Trouble diagnostics toggle filter.buf=0", desc = "LSP code diagnostic", }, -- Gitsigns { "nc", function() gitsigns.nav_hunk("next") end, desc = "Next change", }, { "pc", function() gitsigns.nav_hunk("prev") end, desc = "Previous change", }, -- increment/decrement numbers { "+", "", desc = "Increment number" }, -- increment { "-", "", desc = "Decrement number" }, -- decrement { "to", "tabnew", desc = "Open new tab" }, -- open new tab { "tx", "tabclose", desc = "Close current tab" }, -- close current tab { "tn", "tabn", desc = "Go to next tab" }, -- go to next tab { "tp", "tabp", desc = "Go to previous tab" }, -- go to previous tab { "tf", "tabnew %", desc = "Open current buffer in new tab" }, -- move current buffer to new tab { "", ":noh", desc = "clears search highlights", noremap = true, silent = true, }, { "ib", function() print(vim.bo.filetype) end, desc = "Print the filetype of current buffer", }, -- { "uh", function() require("edgy").select("left") end, desc = "focus left" }, }, { mode = "v", { "", ":m '>+1gv=gv", desc = "Move selection down" }, { "", ":m '<-2gv=gv", desc = "Move selection up" }, -- Comment { "/", "gc", desc = "comment toggle", remap = true }, { "", ":noh", desc = "clears search highlights", noremap = true, silent = true, }, }, })