diff options
| author | Mike Vink <mike@pionative.com> | 2025-02-08 08:16:07 +0100 |
|---|---|---|
| committer | Mike Vink <mike@pionative.com> | 2025-02-08 08:16:07 +0100 |
| commit | 7d30d2272ef59166c1b382cab324a400a42d577d (patch) | |
| tree | 8f153f04818c7622b9cd2a3e1a18f9dcce1a1104 /.config/nvim/lua | |
| parent | fd48011d2ef530b392df72e8685da4e8a2a54d1d (diff) | |
copy config
Diffstat (limited to '.config/nvim/lua')
| -rw-r--r-- | .config/nvim/lua/my/events.lua | 120 | ||||
| -rw-r--r-- | .config/nvim/lua/my/init.lua | 550 | ||||
| -rw-r--r-- | .config/nvim/lua/my/lsp.lua | 46 | ||||
| -rw-r--r-- | .config/nvim/lua/my/packages/blink.lua | 57 | ||||
| -rw-r--r-- | .config/nvim/lua/my/packages/dap.lua | 125 | ||||
| -rw-r--r-- | .config/nvim/lua/my/packages/go.lua | 75 | ||||
| -rw-r--r-- | .config/nvim/lua/my/packages/init.lua | 6 | ||||
| -rw-r--r-- | .config/nvim/lua/my/packages/lint.lua | 26 | ||||
| -rw-r--r-- | .config/nvim/lua/my/packages/lualine.fnl | 17 | ||||
| -rw-r--r-- | .config/nvim/lua/my/packages/luasnip.lua | 44 | ||||
| -rw-r--r-- | .config/nvim/lua/my/packages/oil.lua | 75 | ||||
| -rw-r--r-- | .config/nvim/lua/my/settings.lua | 68 |
12 files changed, 1209 insertions, 0 deletions
diff --git a/.config/nvim/lua/my/events.lua b/.config/nvim/lua/my/events.lua new file mode 100644 index 0000000..933ba19 --- /dev/null +++ b/.config/nvim/lua/my/events.lua @@ -0,0 +1,120 @@ +local lsp = require("my.lsp") +local oil = require("oil") +local lint = require("lint") +local event = vim.api.nvim_create_autocmd +local command = vim.api.nvim_create_user_command + +vim.api.nvim_create_augroup("my", {clear= true}) +vim.api.nvim_create_augroup("conf#events", {clear= true}) + +event( + "User", + {group= "conf#events", + pattern= { "ZoxideDirChanged" }, + callback= function() + vim.schedule(function() + oil.open(vim.fn.getcwd()) + end) + end}) + +event( + "BufReadPost", + {group= "conf#events", + pattern= { "*" }, + callback=function() + local pattern = "'\\s\\+$'" + vim.cmd("syn match TrailingWhitespace " .. pattern) + vim.cmd("hi link TrailingWhitespace IncSearch") + end}) + +event( + "BufWritePost", + {group= "conf#events", + pattern={ "*" }, + callback=function() + lint.try_lint() + vim.schedule(function() vim.diagnostic.setloclist({open= false}) end) + end}) + +local session_file = vim.fn.expand("~/.vimsession.vim") +event( + "VimLeave", + {group= "conf#events", + pattern= { "*" }, + callback=function() + vim.cmd("mksession! " .. session_file) + end}) + +event( + "LspAttach", + {group = "conf#events", + pattern = { "*" }, + callback = function(ev) + lsp.attach({ + client = vim.lsp.get_client_by_id(ev.data.client_id), + buf = ev.buf, + }) + end}) + +event( + "LspAttach", + {group = "conf#events", + pattern = { "*" }, + callback = function(ev) + lsp.attach({ + client = vim.lsp.get_client_by_id(ev.data.client_id), + buf = ev.buf, + }) + end}) + +-- filetypes + +event( + "FileType", { + group="conf#events", + pattern={ "go", "gomod", "gowork", "gotmpl" }, + callback=function(ev) + vim.lsp.start({ + name="gopls", + cmd={ "gopls" }, + root_dir=vim.fs.root(ev.buf, {"go.work", "go.mod", ".git"}) + }) + end, + }) + +event( + "FileType", { + group="conf#events", + pattern={ "python" }, + callback=function(ev) + vim.lsp.start({ + name="basedpyright", + cmd={ "basedpyright-langserver", "--stdio" }, + settings={ + basedpyright = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "openFilesOnly", + useLibraryCodeForTypes = true, + autoImportCompletions = true, + inlayHints = { + variableTypes = true, + callArgumentNames = true, + functionReturnTypes = true, + genericTypes = true, + }, + }, + }, + }, + root_dir=vim.fs.root(ev.buf, { + 'pyproject.toml', + 'setup.py', + 'setup.cfg', + 'requirements.txt', + 'Pipfile', + 'pyrightconfig.json', + '.git', + }) + }) + end, + }) diff --git a/.config/nvim/lua/my/init.lua b/.config/nvim/lua/my/init.lua new file mode 100644 index 0000000..76bf1f0 --- /dev/null +++ b/.config/nvim/lua/my/init.lua @@ -0,0 +1,550 @@ +require("my.settings") +_G.P = function(...) + vim.iter({...}):map(vim.inspect):each(print) +end +_G.ternary = function ( cond , T , F ) + if cond then return T else return F end +end +vim.cmd "colorscheme kanagawa-wave" + +vim.cmd "filetype plugin on" +vim.cmd "filetype indent on" +vim.cmd "highlight WinSeparator guibg=None" +vim.cmd "packadd cfilter" + +vim.api.nvim_set_hl(0, "VirtualTextWarning", {link= "Grey"}) +vim.api.nvim_set_hl(0, "VirtualTextError", {link= "DiffDelete"}) +vim.api.nvim_set_hl(0, "VirtualTextInfo", {link= "DiffChange"}) +vim.api.nvim_set_hl(0, "VirtualTextHint", {link= "DiffAdd"}) +vim.diagnostic.config({virtual_text = false, virtual_lines = { highlight_whole_line = false, only_current_line = true } }) + +local map = vim.keymap.set +local unmap = vim.keymap.del +function i_grep(word, file) + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes( + ":silent grep " + .. ternary(not (word == ""), word .. " ", "") + .. file:gsub("oil://", "") + .. "<c-f>B<left>i<space>", + true, false, true + ), + "n", false + ) +end + +function cope() + require("quicker").refresh() + vim.cmd(":botright copen " .. math.floor(vim.o.lines / 2.1)) +end + +map("n", "gb", ":GBrowse<CR>") +map("n", "g<cr>", ":G<cr>") +map("n", "ge", function() vim.diagnostic.open_float() end) +map("n", "-", ":Oil<cr>") +map("n", "<leader>qf", cope) +map("n", "<leader>q<BS>", ":cclose<cr>") +map("n", "<leader>ll", ":lopen<cr>") +map("n", "<leader>l<BS>", ":lclose<cr>") +map("n", "<M-h>", cope) +map("n", "<C-n>", ":cnext<cr>") +map("n", "<C-p>", ":cprev<cr>") +map("n", "<C-a>", ":Rerun<CR>") +map("n", "<C-s>", function() + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes( + ":Sh<up><c-f>", + true, false, true + ), + "n", false + ) + vim.schedule(function() + vim.cmd("let v:searchforward = 0") + map("n","/","/Sh.*",{buffer=true}) + map("n","?","?Sh.*",{buffer=true}) + end) +end) +map("n", "<C-x>", function() + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes( + ":Compile<up><c-f>", + true, false, true + ), + "n", false + ) + vim.schedule(function() + vim.cmd("let v:searchforward = 0") + map("n","/","/Compile.*",{buffer=true}) + map("n","?","?Compile.*",{buffer=true}) + end) +end) +map("n", "[q",":cprevious<cr>") +map("n", "]q",":cnext<cr>") +map("n", "[x",":lprevious<cr>") +map("n", "]x",":lnext<cr>") +map("n", "[g",":GV<cr>") +map("n", "]g",":GV?<cr>") +map("n", "]G",":GV!<cr>") +map("n", "<leader>:", function() i_grep("<c-r><c-w>", vim.fn.bufname("%")) end) +map("v", "<leader>:", ":Vgrep!<cr>") +map("n", "<leader>;", function() i_grep("", vim.fn.fnamemodify(vim.fn.bufname("%"), ":h")) end) +map("v", "<leader>;", ":Vgrep<cr>") +map("n", "<leader>'", ":Find ") +map("n", "<leader>x<cr>", function() vim.cmd "b #" end) + +require("nvim_comment").setup() + +local oil_actions = require("oil.actions") +map("n", "_", oil_actions.open_cwd.callback) + +local fzf = require("fzf-lua") +local action = (require "fzf-lua.actions") +fzf.setup {"max-perf"} +fzf.register_ui_select() +map("n", "<leader>xp", fzf.files) +map("n", "<leader>xa", fzf.args) +map("n", "<leader>x;", fzf.quickfix) +map("n", "<leader>xb", function() + fzf.buffers({ + actions={default={fn=action.buf_edit_or_qf}} + }) +end) + +local obsidian = require("obsidian") +obsidian.setup { workspaces = { + { name = "notes", path = ternary(vim.fn.isdirectory(vim.fn.expand("~/Sync/my/notes")) == 1, "~/Sync/my/notes", "~/sync/my/notes")} +}} + + +vim.api.nvim_create_user_command( + "Vgrep", +function(cmd) + local buf, lrow, lcol = unpack(vim.fn.getpos("'<")) + local buf, rrow, rcol = unpack(vim.fn.getpos("'>")) + -- (local [line & rest] (vim.api.nvim_buf_get_text 0 (- <row 1) (- <col 1) (- >row 1) >col {})) + local firstline = + vim.iter(vim.api.nvim_buf_get_text(0, lrow-1, lcol-1, rrow-1, rcol, {})) + :next() + if cmd.bang then + i_grep(firstline, vim.fn.bufname("%")) + else + i_grep(firstline, vim.fn.fnamemodify(vim.fn.bufname("%"), ":h")) + end +end, + {range= 1, bang=true} +) + +vim.api.nvim_create_user_command( + "NixEdit", +function(cmd) + local f = io.popen("nix eval --raw /nix-config#nixosConfigurations." .. vim.fn.hostname() .. ".pkgs." .. cmd.args) + vim.cmd("e " .. f:read()) +end, + {nargs=1} +) + + +local last_job_state = nil +local last_job_thunk = nil +local last_job_lines = "" +function qf(inputs, opts) + local id, title = inputs.id, inputs.title + local prettify = function(line) + local l = line:gsub("%c+%[[0-9:;<=>?]*[!\"#$%%&'()*+,-./]*[@A-Z%[%]^_`a-z{|}~]*;?[A-Z]?", "") + return l + end + local in_qf = function() + return vim.opt_local.buftype:get() == "quickfix" + end + local is_at_last_line = function() + local row, _ = vim.api.nvim_win_get_cursor(0) + local last_line = vim.api.nvim_buf_line_count(0) + return row == last_line + end + return function(lines) + lines = vim.iter(lines):map(prettify):totable() + vim.schedule(function() + local what = { + id=id, + title=title, + lines=lines, + efm=opts.efm, + } + vim.fn.setqflist( + {}, "a", what + ) + if (not in_qf()) or (is_at_last_line() and in_qf()) then + vim.cmd ":cbottom" + end + end) + end +end + +function qfjob(cmd, stdin, opts) + last_job_lines = "" + local opts = opts or {} + opts.filter = opts.filter or (function(line) + return line + end) + + local title = table.concat(cmd, " ") + vim.fn.setqflist({}, " ", {title=title}) + local append_lines = qf(vim.fn.getqflist({id=0,title=1}), opts) + last_job_state = vim.system( + cmd, { + stdin=stdin, + stdout=function(err,data) + if data then + if not opts.buffer then + append_lines(vim.iter(data:gmatch("[^\n]+")):map(opts.filter)) + else + last_job_lines = last_job_lines .. data + end + end + end, + stderr=function(err,data) + if data then + if not opts.buffer then + append_lines(vim.iter(data:gmatch("[^\n]+")):map(opts.filter)) + else + last_job_lines = last_job_lines .. data + end + end + end, + }, + function(job) + vim.schedule(function() + if opts.buffer then + append_lines(vim.iter(last_job_lines:gmatch("[^\n]+")):map(opts.filter)) + end + + local winnr = vim.fn.winnr() + if not (job.code == 0) then + cope() + if not (winnr == vim.fn.winnr()) then + vim.notify([["]] .. title .. [[" failed!]]) + vim.cmd "wincmd p | cbot" + end + else + if opts.open then + cope() + end + vim.notify([["]] .. title .. [[" succeeded!]]) + end + end) + end) +end + +vim.api.nvim_create_user_command( + "Find", + function(cmd) + local bufs = vim.iter(vim.api.nvim_list_bufs()) + :fold({}, function(acc, b) + acc[vim.api.nvim_buf_get_name(b)] = vim.api.nvim_buf_get_mark(b, [["]]) + return acc + end) + qfjob({ "fdfind", "--absolute-path", "--type", "f", "-E", vim.fn.expand("%:."), cmd.args }, nil, {efm = "%f:%l:%c:%m", open = true, filter = function(line) + local pos = bufs[line] or {} + local lnum, col = (pos[1] or "1"), (pos[2] or "0") + return line .. ":" .. lnum .. ":" .. col .. ":" .. "hello" + end}) + end, + {nargs="*", bang=true, complete="file"}) + +function opts_for_args(args) + local opts = { + go = { + test = function(cmd) + return {buffer = true, efm=require('my.packages.go').efm()} + end + } + } + local arg_opts = vim.iter(args) + :fold(opts, function(acc, v) + if type(acc) == "table" and acc[v] then + return acc[v] + end + return acc + end) + if type(arg_opts) == "function" then + return arg_opts() + elseif type(arg_opts) == "table" then + return (arg_opts[1] or function() return {} end)() + end +end + +vim.api.nvim_create_user_command( + "Sh", + function(cmd) + local thunk = function() qfjob({ "nu", "--commands", cmd.args }, nil, opts_for_args(cmd.fargs)) end + last_job_thunk = thunk + thunk() + end, + {nargs="*", bang=true, complete="shellcmd"}) + +vim.api.nvim_create_user_command( + "Rerun", + function(cmd) + if not last_job_state then + vim.notify "nothing to rerun" + else + if not last_job_state:is_closing() then + vim.notify "Last job not finished" + else + last_job_thunk() + end + end + end, {bang=true}) + +vim.api.nvim_create_user_command( + "Stop", + function() + if last_job_state then + last_job_state:kill() + vim.notify "killed job" + else + vim.notify "nothing to do" + end + end, {bang=true}) + +local browse_git_remote = function(fugitive_data) + local path = fugitive_data.path + if not path then + local bufname = vim.fn.bufname("%") + if vim.startswith(bufname,"oil://") then + local d = "oil://" .. vim.fs.dirname(fugitive_data.git_dir) .. "/" + path = bufname:sub(d:len()+1, bufname:len()) + end + end + assert(path) + + local home, org, project, repo = "", "" + if vim.startswith(fugitive_data.remote, "git@") then + home, repo = fugitive_data.remote:match("git@([^:]+):(.*)%.git") + if not (home and repo) then + home, org, project, repo = fugitive_data.remote:match("git@([^:]+):.*/(.*)/(.*)/(.*)") + end + end + assert((home and org and project and repo) or (home and repo)) + + local homes = { + ["ssh.dev.azure.com"] = "dev.azure.com", + } + if homes[home] then + home = homes[home] + end + + local urls = { + ["bitbucket.org"] = { + ["tree"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/src/" .. fugitive_data.commit .. "/" .. path + end, + ["blob"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/src/" .. fugitive_data.commit .. "/" .. path + end, + ["commit"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/commits/" .. fugitive_data.commit + end, + ["ref"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/commits/" .. fugitive_data.commit + end, + }, + ["dev.azure.com"] = { + ["tree"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. org .. "/" .. project .. "/_git/" .. repo .. "?version=GB" .. fugitive_data.commit .. "&path=/" .. path + end, + ["blob"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. org .. "/" .. project.. "/_git/" .. repo .. "?version=GB" .. fugitive_data.commit .. "&path=/" .. path + end, + ["commit"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. org .. "/" .. project.. "/_git/" .. repo .. "/commit/" .. fugitive_data.commit + end, + ["ref"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. org .. "/" .. project.. "/_git/" .. repo .. "/commit/" .. fugitive_data.commit + end, + }, + ["gitlab.com"] = { + ["tree"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/-/tree/" .. fugitive_data.commit .. "/" .. path + end, + ["blob"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/-/blob/" .. fugitive_data.commit .. "/" .. path + end, + ["commit"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/-/commit/" .. fugitive_data.commit + end, + ["ref"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/-/commit/" .. fugitive_data.commit + end, + }, + ["github.com"] = { + ["tree"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/tree/" .. fugitive_data.commit .. "/" .. path + end, + ["blob"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/blob/" .. fugitive_data.commit .. "/" .. path + end, + ["commit"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/commit/" .. fugitive_data.commit + end, + ["ref"] = function(home, org, project, repo) + return "https://" .. home .. "/" .. repo .. "/commit/" .. fugitive_data.commit + end, + }, + } + + return urls[home][fugitive_data.type](home, org, project, repo) +end +vim.g.fugitive_browse_handlers = { browse_git_remote } + +-- require("lsp_signature").setup() +require("nvim-treesitter.configs").setup({highlight = {enable = true}}) +require("gitsigns").setup({ + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = 'right_align', -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + virt_text_priority = 100, + use_focus = true, + }, +}) + +vim.opt.clipboard:append({"unnamedplus"}) + +local osc52 = require("vim.ui.clipboard.osc52") + +function paste() + return { + vim.fn.split(vim.fn.getreg(""), "\n"), + vim.fn.getregtype("") + } +end +-- function xclip(lines) +-- vim.system({ "nu", "--commands", "xclip -f -sel c | xclip"}, {stdin=lines, text=true}, nil) +-- end +function pbcopy(lines) + vim.system({ "nu", "--commands", "pbcopy"}, {stdin=lines, text=true}, nil) +end + +-- Unix, Linux variants +local fh, err = assert(io.popen("which pbcopy 2>/dev/null", "r")) +if fh:read() then + vim.g.clipboard = { + name = 'pbcopy Clipboard', + copy = { + ['+'] = pbcopy, + ['*'] = pbcopy, + }, + paste = { + ['+'] = paste, + ['*'] = paste, + }, + } +else + vim.g.clipboard = { + name = 'OSC 52', + copy = { + ['+'] = require('vim.ui.clipboard.osc52').copy('+'), + ['*'] = require('vim.ui.clipboard.osc52').copy('*'), + }, + paste = { + ['+'] = require('vim.ui.clipboard.osc52').paste('+'), + ['*'] = require('vim.ui.clipboard.osc52').paste('*'), + }, + } +end +require("my.events") +require("my.packages") + +-- require('render-markdown').setup ({ +-- opts = { +-- file_types = { "markdown", "Avante" }, +-- }, +-- ft = { "markdown", "Avante" },}) +-- require('avante_lib').load() +-- -- require('copilot').setup {} +-- require('avante').setup ({ +-- provider = "openai", +-- openai = { +-- model = "gpt-4o", +-- }, +-- behaviour = { +-- auto_suggestions = false, +-- auto_set_highlight_group = true, +-- auto_set_keymaps = true, +-- auto_apply_diff_after_generation = false, +-- support_paste_from_clipboard = false, +-- }, +-- mappings = { +-- --- @class AvanteConflictMappings +-- diff = { +-- ours = "co", +-- theirs = "ct", +-- all_theirs = "ca", +-- both = "cb", +-- cursor = "cc", +-- next = "]x", +-- prev = "[x", +-- }, +-- suggestion = { +-- accept = "<M-l>", +-- next = "<M-]>", +-- prev = "<M-[>", +-- dismiss = "<C-]>", +-- }, +-- jump = { +-- next = "]]", +-- prev = "[[", +-- }, +-- submit = { +-- normal = "<CR>", +-- insert = "<C-s>", +-- }, +-- sidebar = { +-- apply_all = "A", +-- apply_cursor = "a", +-- switch_windows = "<Tab>", +-- reverse_switch_windows = "<S-Tab>", +-- }, +-- }, +-- }) + +require("quicker").setup({ + keys = { + { + ">", + function() + require("quicker").expand({ before = 2, after = 2, add_to_existing = true }) + end, + desc = "Expand quickfix context", + }, + { + "<", + function() + require("quicker").collapse() + end, + desc = "Collapse quickfix context", + }, + }, +}) +-- (local +-- draw +-- (fn [toggle] +-- (if +-- toggle +-- (do +-- (vim.cmd "set virtualedit=all") +-- (vim.keymap.set :v "<leader>;" "<esc>:VBox<CR>") +-- (vim.keymap.set "n" "J" "<C-v>j:VBox<CR>") +-- (vim.keymap.set "n" "K" "<C-v>k:VBox<CR>") +-- (vim.keymap.set "n" "L" "<C-v>l:VBox<CR>") +-- (vim.keymap.set "n" "H" "<C-v>h:VBox<CR>")) +-- (do +-- (vim.cmd "set virtualedit=") +-- (vim.keymap.del :v "<leader>;") +-- (vim.keymap.del "n" "J") +-- (vim.keymap.del "n" "K") +-- (vim.keymap.del "n" "L") +-- (vim.keymap.del "n" "H"))))) diff --git a/.config/nvim/lua/my/lsp.lua b/.config/nvim/lua/my/lsp.lua new file mode 100644 index 0000000..2fad5aa --- /dev/null +++ b/.config/nvim/lua/my/lsp.lua @@ -0,0 +1,46 @@ +function set_buf_opt(buf, name, value) + return function() vim.api.nvim_buf_set_option(buf, name, value) end +end + +function buf_map(mode, key, fn) + return function() vim.keymap.set(mode, key, fn, {silent= true, noremap = true, buffer = 0}) end +end + +function lsp_action(action) + return vim.lsp.buf[action] +end + +local capability_map = { + -- completionProvider = (set_buf_opt :omnifunc "v:lua.vim.lsp.omnifunc"), + -- hoverProvider = set_buf_opt("keywordprg", ":LspHover"), + renameProvider = buf_map("n", "<leader>gr", lsp_action("rename")), + signatureHelpProvider = buf_map("n", "<leader>gs", lsp_action("signature_help")), + definitionProvider = buf_map("n", "<leader>gd", lsp_action("definition")), + declaration = buf_map("n", "<leader>gD", lsp_action("declaration")), + implementationProvider = buf_map("n", "<leader>gi", lsp_action("implementation")), + referencesProvider = buf_map("n", "<leader>gg", lsp_action("references")), + documentSymbolProvider = buf_map("n", "<leader>gds", lsp_action("workspace_symbol")), + codeActionProvider = buf_map("n", "<leader>ga", lsp_action("code_action")), + codeLensProvider = buf_map("n", "<leader>gl", vim.lsp.codelens.run), + inlayHintProvider = function() + vim.lsp.inlay_hint.enable(true) + buf_map("n", "<leader>gh", function() vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled(0)) end) + end, + documentFormattingProvider = function() + set_buf_opt("formatexpr", "v:lua.vim.lsp.format()") + buf_map("n", "<leader>gq", function() vim.lsp.buf.format({async= true}) end) + end, +} + +local M = {} + +M.attach = function (ev) + vim.iter(ev.client.server_capabilities) + :each(function(c) + local fn = capability_map[c] + if fn then fn() end + end) + ev.client.capabilities = require('blink.cmp').get_lsp_capabilities(ev.client.capabilities) +end + +return M diff --git a/.config/nvim/lua/my/packages/blink.lua b/.config/nvim/lua/my/packages/blink.lua new file mode 100644 index 0000000..31726dc --- /dev/null +++ b/.config/nvim/lua/my/packages/blink.lua @@ -0,0 +1,57 @@ +local blink = require('blink.cmp') +blink.setup { + fuzzy = { prebuilt_binaries = { force_version = "v0.10.0" } }, + -- 'default' for mappings similar to built-in completion + -- 'super-tab' for mappings similar to vscode (tab to accept, arrow keys to navigate) + -- 'enter' for mappings similar to 'super-tab' but with 'enter' to accept + -- See the full "keymap" documentation for information on defining your own keymap. + keymap = { preset = 'default' }, + + appearance = { + -- Sets the fallback highlight groups to nvim-cmp's highlight groups + -- Useful for when your theme doesn't support blink.cmp + -- Will be removed in a future release + use_nvim_cmp_as_default = true, + -- Set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- Adjusts spacing to ensure icons are aligned + nerd_font_variant = 'mono' + }, + + -- Default list of enabled providers defined so that you can extend it + -- elsewhere in your config, without redefining it, due to `opts_extend` + sources = { + default = { 'lsp', 'path', 'snippets', 'buffer' }, + }, + + snippets = { preset = 'luasnip' }, +} + +local map = vim.keymap.set +local unmap = vim.keymap.del +local event = vim.api.nvim_create_autocmd +map("n", "<leader>xf", function() + event({"CmdwinEnter"}, { + once = true, + callback = function() + map("i","<c-j>", function() + blink.hide() + vim.schedule(function() + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes("<cr>", true, false, true), + "c", false) + end) + end,{buffer=true}) + map("i","<bs>","<c-o>vT/d",{buffer=true}) + end + }) + event({"CmdwinLeave"}, { + once = true, + callback = function() + unmap("i","<c-j>",{buffer=true}) + unmap("i","<bs>",{buffer=true}) + end + }) + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes(":edit <c-r>=expand('%:p:h')<cr><c-f>A/", true, false, true), + "c", false) +end) diff --git a/.config/nvim/lua/my/packages/dap.lua b/.config/nvim/lua/my/packages/dap.lua new file mode 100644 index 0000000..c9240f9 --- /dev/null +++ b/.config/nvim/lua/my/packages/dap.lua @@ -0,0 +1,125 @@ +local dap = require("dap") +local adapters = dap.adapters +local configurations = dap.configurations + +local dapui = require("dapui") +local dappy = require("dap-python") + +adapters.delve = { + type="server", + port="${port}", + executable={ + command="dlv", + args= { "dap", "-l", "127.0.0.1:${port}" } + } +} + +configurations.go = { + {type = "delve", + name = "Debug", + request = "launch", + env = {CGO_CFLAGS="-Wno-error=cpp"}, + program = "${file}"}, + {type = "delve", + name = "DebugTest", + request = "launch", + mode = "test", + env = {CGO_CFLAGS="-Wno-error=cpp"}, + program = "${file}"}, + {type = "delve", + name = "DebugTerraform", + request = "launch", + program = "${file}", + env = {CGO_CFLAGS="-Wno-error=cpp"}, + args = { "-debug" }}, + {type = "delve", + name = "DebugTerraformAcc", + request = "launch", + program = "${file}", + mode = "test", + env = {CGO_CFLAGS="-Wno-error=cpp", TF_ACC=1}}, + {type = "delve", + name = "DebugTestSuite", + request = "launch", + mode = "test", + env = {CGO_CFLAGS="-Wno-error=cpp"}, + program = "${fileDirname}"}, +} + +dapui.setup { + expand_lines=false, + layouts={ + {position="bottom", size=10, elements={ {id="repl", size=0.5}, {id="console", size=0.5} }}, + {position="left", size=40, elements={ {id="breakpoints",size=0.25}, {id="stacks", size=0.25}, {id="watches", size=0.25}, {id="scopes", size=0.25} }}, + {position="bottom", size=25, elements={ {id="repl", size=0.35}, {id="watches", size=0.65} }}, + } +} + +dappy.setup() + +-- (local run_table +-- {:python +-- (fn [fname] +-- { +-- :name (.. "Launch " fname) +-- :program fname +-- :console "externalTerminal" +-- :request "launch" +-- :type "python" +-- :cwd :/Users/ivi/Programming +-- :waitOnAbnormalExit true +-- :waitOnNormalExit true})}) +-- (vim.keymap.set +-- :n +-- "s;" +-- (fn [] +-- (local fname (vim.fn.fnamemodify (vim.fn.bufname "%") ":p")) +-- (local get_config (. run_table (vim.opt_local.ft:get))) +-- +-- (set dap.defaults.fallback.external_terminal +-- {:command :/Applications/Alacritty.app/Contents/MacOS/alacritty +-- :args [:-T :dap :--working-directory (vim.fn.getcwd) :-e]}) +-- +-- (if get_config +-- (dap.run (get_config fname))))) + + +vim.keymap.set("n", "si", + function() + dapui.toggle {layout=1, reset=true} + dapui.toggle {layout=2, reset=true} + end, {silent=true}) + +vim.keymap.set("n", "s<enter>", function() dapui.toggle {layout=3, reset=true} end, {silent=true}) +-- ;; "breakpoints", +-- ;; "repl", +-- ;; "scopes", +-- ;; "stacks", +-- ;; "watches", +-- ;; "hover", +-- ;; "console",) +vim.keymap.set("n", "sfw", + function() + dapui.float_element("watches", {width=vim.api.nvim_win_get_width(0), height=30, enter=true}) + end, {silent=true}) + +vim.keymap.set("n", "sfs", + function() + dapui.float_element("scopes", {width=vim.api.nvim_win_get_width(0), height=30, enter=true}) + end, {silent=true}) + +vim.keymap.set("n", "sq", dap.terminate, {silent=true}) +vim.keymap.set("n", "sc", dap.continue, {silent=true}) +vim.keymap.set("n", "sr", dap.run_to_cursor, {silent=true}) +vim.keymap.set("n", "sn", dap.step_over, {silent=true}) +vim.keymap.set("n", "ss", dap.step_into, {silent=true}) +vim.keymap.set("n", "so", dap.step_out, {silent=true}) +vim.keymap.set("n", "sb", dap.toggle_breakpoint, {silent=true}) +vim.keymap.set("n", "sB", dap.set_breakpoint, {silent=true}) +vim.keymap.set("n", "slp", + function() + dap.set_breakpoint(nil, nil, vim.fn.input("Log point message: ")) + end, {silent=true}) + +vim.keymap.set("n", "st", dap.repl.toggle, {silent=true}) +vim.keymap.set("n", "sl", dap.run_last, {silent=true}) diff --git a/.config/nvim/lua/my/packages/go.lua b/.config/nvim/lua/my/packages/go.lua new file mode 100644 index 0000000..4abf384 --- /dev/null +++ b/.config/nvim/lua/my/packages/go.lua @@ -0,0 +1,75 @@ +local M = {} +local go = require("go") +local gotest = require("go.gotest") +go.setup { + test_efm = false, -- errorfomat for quickfix, default mix mode, set to true will be efm only + luasnip = true, + + goimports = false, + fillstruct = false, + gofmt = false, + max_line_len = nil, + tag_transform = false, + test_dir = false, + comment_placeholder = " ", + icons = false, + verbose = false, + log_path = vim.fn.expand("~/tmp/gonvim.log"), + lsp_cfg = false, + lsp_gofumpt = false, + lsp_on_attach = nil, + lsp_keymaps = false, + lsp_codelens = false, + diagnostic = false, + lsp_inlay_hints = {enable= false}, + gopls_remote_auto = false, + gocoverage_sign = "█", + sign_priority = 7, + dap_debug = false, + dap_debug_gui = false, + dap_debug_keymap = false, + dap_vt = false, + textobjects = false, + gopls_cmd = nil, + build_tags = "", + test_runner = "go", + run_in_floaterm = false, + iferr_vertical_shift = 4, +} + +local efm = function() + local indent = [[%\\%( %\\)]] + local efm = [[%-G=== RUN %.%#]] + efm = efm .. [[,%-G]] .. indent .. [[%#--- PASS: %.%#]] + efm = efm .. [[,%G--- FAIL: %\\%(Example%\\)%\\@= (%.%#)]] + efm = efm .. [[,%G]] .. indent .. [[%#--- FAIL: (%.%#)]] + efm = efm .. [[,%A]] .. indent .. [[%\\+%[%^:]%\\+: %f:%l: %m]] + efm = efm .. [[,%+Gpanic: test timed out after %.%\\+]] + efm = efm .. ',%+Afatal error: %.%# [recovered]' + efm = efm .. [[,%+Afatal error: %.%#]] + efm = efm .. [[,%+Apanic: %.%#]] + -- + -- -- exit + efm = efm .. ',%-Cexit status %[0-9]%\\+' + efm = efm .. ',exit status %[0-9]%\\+' + -- -- failed lines + efm = efm .. ',%-CFAIL%\\t%.%#' + efm = efm .. ',FAIL%\\t%.%#' + -- compiling error + + efm = efm .. ',%A%f:%l:%c: %m' + efm = efm .. ',%A%f:%l: %m' + efm = efm .. ',%f:%l +0x%[0-9A-Fa-f]%\\+' -- pannic with adress + efm = efm .. ',%-G%\\t%\\f%\\+:%\\d%\\+ +0x%[0-9A-Fa-f]%\\+' -- test failure, address invalid inside + -- multi-line + efm = efm .. ',%+G%\\t%m' + -- efm = efm .. ',%-C%.%#' -- ignore rest of unmatched lines + -- efm = efm .. ',%-G%.%#' + + efm = string.gsub(efm, ' ', [[\ ]]) + -- log(efm) + return efm +end +gotest.efm = efm +M.efm = efm +return M diff --git a/.config/nvim/lua/my/packages/init.lua b/.config/nvim/lua/my/packages/init.lua new file mode 100644 index 0000000..9c3a65f --- /dev/null +++ b/.config/nvim/lua/my/packages/init.lua @@ -0,0 +1,6 @@ +require("my.packages.oil") +require("my.packages.blink") +require("my.packages.lint") +require("my.packages.luasnip") +require("my.packages.dap") +require("my.packages.go") diff --git a/.config/nvim/lua/my/packages/lint.lua b/.config/nvim/lua/my/packages/lint.lua new file mode 100644 index 0000000..815f9b3 --- /dev/null +++ b/.config/nvim/lua/my/packages/lint.lua @@ -0,0 +1,26 @@ +local lint = require("lint") +local conform = require("conform") + +function is_executable(program) + return vim.fn.executable(program) == 1 +end + +lint.linters_by_ft = { + markdown=ternary(is_executable("vale"), { "vale" }, {}), + python=ternary(is_executable("ruff"), { "ruff" }, {}), + sh={ "shellcheck" }, +} + +conform.setup { + formatters_by_ft={ + python= { "ruff_format", "isort" }, + go= { "goimports" }, + nix= { "alejandra" }, + terraform= { "terraform_fmt" }, + hcl= { "terraform_fmt" }, + }, + format_on_save={ + timeout_ms= 500, + lsp_fallback= false + } +} diff --git a/.config/nvim/lua/my/packages/lualine.fnl b/.config/nvim/lua/my/packages/lualine.fnl new file mode 100644 index 0000000..4f57425 --- /dev/null +++ b/.config/nvim/lua/my/packages/lualine.fnl @@ -0,0 +1,17 @@ +(local lualine (require :lualine)) +(local clients #(do + (local bn (vim.fn.fnamemodify (vim.fn.bufname :%) ::p)) + (local m (bn:match ".*clients/([a-z]+)/.*")) + (if (not= nil m) + m + ""))) +(lualine.setup + {:extensions [:quickfix :fugitive :oil :fzf :nvim-dap-ui] + :sections + {:lualine_c ["%=" {1 clients :color :WarningMsg}]} + :winbar + {:lualine_a [:filename]} + :inactive_winbar + {:lualine_a [:filename]} + :tabline + {:lualine_a [:tabs]}}) diff --git a/.config/nvim/lua/my/packages/luasnip.lua b/.config/nvim/lua/my/packages/luasnip.lua new file mode 100644 index 0000000..338b343 --- /dev/null +++ b/.config/nvim/lua/my/packages/luasnip.lua @@ -0,0 +1,44 @@ +local ls = require("luasnip") +local s = ls.snippet +local sn = ls.snippet_node +local isn = ls.indent_snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local events = require("luasnip.util.events") +local ai = require("luasnip.nodes.absolute_indexer") +local extras = require("luasnip.extras") +local l = extras.lambda +local rep = extras.rep +local p = extras.partial +local m = extras.match +local n = extras.nonempty +local dl = extras.dynamic_lambda +local fmt = require("luasnip.extras.fmt").fmt +local fmta = require("luasnip.extras.fmt").fmta +local conds = require("luasnip.extras.expand_conditions") +local postfix = require("luasnip.extras.postfix").postfix +local types = require("luasnip.util.types") +local parse = require("luasnip.util.parser").parse_snippet +local ms = ls.multi_snippet +local k = require("luasnip.nodes.key_indexer").new_key + +vim.keymap.set( { "i", }, "<C-K>", ls.expand, {silent= true}) +vim.keymap.set( { "i", "s" }, "<C-L>", function() if ls.expand_or_jumpable() then ls.expand_or_jump(1) end end, {silent=true}) +vim.keymap.set( { "i", "s" }, "<C-J>", function() ls.jump(-1) end, {silent=true}) +vim.keymap.set( { "i", "s" }, "<C-E>", function() + if ls.choice_active() then + ls.change_choice(1) + end +end, {silent=true}) + +ls.add_snippets( + "go", { + s("echo", { t("fmt.Println("), i(1), t(")"), i(2) }), + s("echof", { t("fmt.Printf(\"%v\\n\", "), i(1), t(")"), i(2) }), + s("log", { t("fmt.Println("), i(1), t(")"), i(2) }), + s("logf", { t("fmt.Printf(\"%v\\n\", "), i(1), t(")"), i(2) }), + }) diff --git a/.config/nvim/lua/my/packages/oil.lua b/.config/nvim/lua/my/packages/oil.lua new file mode 100644 index 0000000..fa66001 --- /dev/null +++ b/.config/nvim/lua/my/packages/oil.lua @@ -0,0 +1,75 @@ +local oil=require("oil") +local fzf=require("fzf-lua") +local map = vim.keymap.set +local unmap = vim.keymap.del + +oil.setup({ + default_file_explorer = true, + skip_confirm_for_simple_edits = true, + + columns = {"size","permissions"}, + view_options = { + show_hidden = false, + is_hidden_file = function(name, bufnr) + return vim.startswith(name, ".") + end, + is_always_hidden = function(name, bufnr) return false end, + sort = { {"type" ,"asc"}, {"name","asc"} } + }, + + + keymaps = { + ["g?"] = "actions.show_help", + ["<CR>"] = "actions.select", + ["<C-s>"] = function() + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes( + ":Sh<up><c-f>", + true, false, true + ), + "n", false + ) + vim.schedule(function() + vim.cmd("let v:searchforward = 0") + map("n","/","/Sh.*",{buffer=true}) + map("n","?","?Sh.*",{buffer=true}) + end) + end, + [ "<C-h>" ] = "actions.select_split", + [ "<C-t>" ] = "actions.select_tab", + [ "<C-p>" ] = fzf.files, + [ "<C-c>" ] = "actions.close", + [ "<C-l>" ] = "actions.refresh", + [ "." ] = "actions.open_cmdline", + [ "gx" ] = { + callback = function() + local file, dir = oil.get_cursor_entry(), oil.get_current_dir() + if dir and file then + vim.cmd("argadd " .. dir .. file.name) + vim.cmd "args" + end + end + }, + [ "gX" ] = { + callback = function() + local file, dir = oil.get_cursor_entry(), oil.get_current_dir() + if dir and file then + vim.cmd("argdel " .. dir .. file.name) + vim.cmd "args" + end + end + }, + [ "gc" ] = { + callback = function() + vim.cmd("argdel *") + vim.cmd("args") + end + }, + [ "-" ] = "actions.parent", + [ "_" ] = "actions.open_cwd", + [ "cd" ] = "actions.cd", + [ "~" ] = "actions.tcd", + [ "gs" ] = "actions.change_sort", + [ "g." ] = "actions.toggle_hidden" + } +}) diff --git a/.config/nvim/lua/my/settings.lua b/.config/nvim/lua/my/settings.lua new file mode 100644 index 0000000..f08bf16 --- /dev/null +++ b/.config/nvim/lua/my/settings.lua @@ -0,0 +1,68 @@ +vim.g.codeium_enabled = false +vim.g.loaded_2html_plugin = false +vim.g.loaded_fzf = false +vim.g.loaded_health = false +vim.g.loaded_matchit = false +vim.g.loaded_matchparen = nil +vim.g.loaded_netrwPlugin = false +vim.g.loaded_rplugin = false +vim.g.loaded_shada = false +vim.g.loaded_tohtml = false +vim.g.loaded_tutor = false + +vim.g.zoxide_use_select = true +vim.g.zoxide_hook = "pwd" +vim.g.mapleader = " " +vim.g.maplocalleader = " " +vim.g.dirvish_mode = ":sort | sort ,^.*[^/]$, r" + +vim.opt.grepprg = "rg --vimgrep" +vim.opt.grepformat = "%f:%l:%c:%m" +vim.opt.shortmess:append("c") +vim.opt.diffopt:append("vertical") +vim.opt.isfname:append("@-@") +vim.opt.wmw = 10 +vim.opt.inccommand = "split" +vim.opt.signcolumn = "yes" +vim.opt.smd = false +vim.opt.scrolloff = 8 +vim.opt.termguicolors = true +vim.opt.incsearch = true +vim.opt.undofile = true +vim.opt.undodir = vim.fn.expand("~/.local/share/nvim/undo") +vim.opt.backup = false +vim.opt.backupcopy = "yes" +vim.opt.swapfile = false +vim.opt.wrap = false +vim.opt.splitbelow = true +vim.opt.magic = true +vim.opt.showbreak = "+++" +-- vim.opt.; listchars {:eol ""} +vim.opt.list = true +vim.opt.autoread = true +vim.opt.autoindent = true +vim.opt.smartindent = true +vim.opt.expandtab = true +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.hidden = true +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.exrc = true +vim.opt.secure = true +-- vim.opt.; completeopt "menu,longest,preview" +vim.opt.wmnu = true +vim.opt.wop = "pum" +-- vim.opt.; wildmode "list:longest" +vim.opt.complete = ".,w,k,kspell,b" +vim.opt.foldopen = "block,hor,jump,mark,percent,quickfix,search,tag" +vim.opt.laststatus = 3 +-- vim.opt.; winbar "%=%m %f" +vim.opt.winbar = "" +vim.opt.hlsearch = false +vim.opt.showtabline = 1 +vim.opt.cmdheight = 1 + +vim.opt.shellpipe = "out+err>" +vim.opt.shell = "sh" |
