diff options
| author | Mike Vink <59492084+ivi-vink@users.noreply.github.com> | 2024-10-19 18:00:09 +0000 |
|---|---|---|
| committer | Mike Vink <59492084+ivi-vink@users.noreply.github.com> | 2024-10-19 18:00:09 +0000 |
| commit | fea7e9dacc0d4fc5c33890a04e94b7fcd124d347 (patch) | |
| tree | 76ad0c6fa757a5f78fa099a7157c8044db4c90e9 /mut/neovim/lua/my | |
| parent | 62c02a6e17080eb4bde2d09982ab934dc8bbc750 (diff) | |
add lua
Diffstat (limited to 'mut/neovim/lua/my')
| -rw-r--r-- | mut/neovim/lua/my/events.lua | 81 | ||||
| -rw-r--r-- | mut/neovim/lua/my/init.lua | 407 | ||||
| -rw-r--r-- | mut/neovim/lua/my/lsp.lua | 92 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/cmp.lua | 138 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/dap.lua | 125 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/go.lua | 34 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/init.lua | 7 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/lint.lua | 26 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/lualine.fnl | 17 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/luasnip.lua | 41 | ||||
| -rw-r--r-- | mut/neovim/lua/my/packages/oil.lua | 73 | ||||
| -rw-r--r-- | mut/neovim/lua/my/settings.lua | 65 |
12 files changed, 1106 insertions, 0 deletions
diff --git a/mut/neovim/lua/my/events.lua b/mut/neovim/lua/my/events.lua new file mode 100644 index 0000000..fe42daa --- /dev/null +++ b/mut/neovim/lua/my/events.lua @@ -0,0 +1,81 @@ +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}) + +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, + }) diff --git a/mut/neovim/lua/my/init.lua b/mut/neovim/lua/my/init.lua new file mode 100644 index 0000000..6f094ad --- /dev/null +++ b/mut/neovim/lua/my/init.lua @@ -0,0 +1,407 @@ +_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.schedule(function() + vim.cmd "colorscheme kanagawa-wave" +end) + +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.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({"xclip"}, {text= true, stdin=lines}, function(exit) end) + vim.system({"xclip", "-selection", "clipboard"}, {text= true, stdin=lines}, function(exit) end) +end +vim.g.clipboard = { + name = "OSC 52", + copy = { + ["+"] = xclip, ["*"] = xclip + }, + paste = { + ["+"] = paste, ["*"] = paste + } +} + +local oil = require("oil.actions") +local fzf = require("fzf-lua") +local action = (require "fzf-lua.actions") +fzf.setup {"max-perf"} +fzf.register_ui_select() +require("gitsigns").setup() +require("lsp_signature").setup() +require("nvim-treesitter.configs").setup({highlight = {enable = true}}) + +-- (do +-- (local fzf (require "fzf-lua")) +-- ((. fzf "register_ui_select"))) + +-- (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"))))) + +local commenter = require("nvim_comment") +commenter.setup() + +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 +-- (fn i-grep [word file] +-- (vim.api.nvim_feedkeys +-- (vim.api.nvim_replace_termcodes +-- (.. ":silent grep " (if (not= "" word) (.. word " ") "") (file:gsub "oil://" "") "<c-f>B<left>i<space>") true false true) +-- :n false)) +-- (local cope #(vim.cmd (.. ":botright copen " (math.floor (/ vim.o.lines 2.1))))) +function cope() + vim.cmd(":botright copen " .. math.floor(vim.o.lines / 2.1)) +end +local map = vim.keymap.set +-- (let [map vim.keymap.set] +map("n", "gb", ":GBrowse<CR>") +map("n", "g<cr>", ":G<cr>") +map("n", "ge", function() vim.diagnostic.open_float() end) +-- (vim.diagnostic.config {:virtual_text false}) +-- ;(map :n :ga "<Plug>(EasyAlign)") +-- ;(map :x :ga "<Plug>(EasyAlign)") +-- ; (map :n :<leader>d<cr> (fn [] (draw true))) +-- ; (map :n :<leader>d<bs> (fn [] (draw false))) +map("n", "-", ":Oil<cr>") +map("n", "_", oil.open_cwd.callback) + +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>", ":Recompile<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>xp", fzf.files) +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>'", ":silent args `fd `<left>") +map("n", "<leader>xa", fzf.args) +map("n", "<leader>x;", fzf.quickfix) +map("n", "<leader>xb", function() + fzf.buffers({ + keymap={fzf={["alt-a"]="toggle-all"}}, + actions={default={fn=action.buf_edit_or_qf}} + }) +end) +map("n", "<leader>x<cr>", function() vim.cmd "b #" 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 qf +-- (fn [{: id : title}] +-- (fn [lines] +-- (local s (fn [line pattern] +-- (let [(result n) (line:gsub pattern "")] +-- (match n +-- nil line +-- _ result)))) +-- (local prettify #(-> $1 +-- (s "%c+%[[0-9:;<=>?]*[!\"#$%%&'()*+,-./]*[@A-Z%[%]^_`a-z{|}~]*;?[A-Z]?"))) +-- (vim.schedule +-- #(do +-- (local is-qf (= (vim.opt_local.buftype:get) "quickfix")) +-- (local is-at-last-line (let [[row col] (vim.api.nvim_win_get_cursor 0) +-- last-line (vim.api.nvim_buf_line_count 0)] +-- (do +-- (= row last-line)))) +-- (vim.fn.setqflist +-- [] :a +-- {: id : title +-- :lines +-- (icollect [l lines] +-- (do +-- (if (not= l "") +-- (prettify l))))}) +-- (if (or +-- (not is-qf) +-- (and is-at-last-line is-qf)) +-- (vim.cmd ":cbottom"))))))) +-- +-- (var last_job_state nil) +-- (var last_job_thunk nil) +-- (local qfjob +-- (fn [cmd stdin] +-- (local title (table.concat cmd " ")) +-- (vim.fn.setqflist [] " " {: title}) +-- (local add2qf (qf (vim.fn.getqflist {:id 0 :title 1}))) +-- (set +-- last_job_state +-- (vim.system +-- cmd +-- {: stdin +-- :stdout (fn [err data] +-- (if data +-- (add2qf (string.gmatch data "[^\n]+")))) +-- :stderr (fn [err data] +-- (if data +-- (add2qf (string.gmatch data "[^\n]+"))))} +-- (fn [obj] +-- (vim.schedule +-- #(do +-- (set winnr (vim.fn.winnr)) +-- (if (not= obj.code 0) +-- (do +-- (cope) +-- (if (not= (vim.fn.winnr) winnr) +-- (do +-- (vim.notify (.. title " failed, going back")) +-- (vim.cmd "wincmd p | cbot")) +-- (vim.notify (.. title "failed, going back")))) +-- (vim.notify (.. "\"" title "\" succeeded!")))))))))) +-- +-- (vim.api.nvim_create_user_command +-- :Compile +-- (fn [cmd] +-- (local thunk #(qfjob cmd.fargs nil)) +-- (set last_job_thunk thunk) +-- (thunk)) +-- {:nargs :* :bang true :complete "file"}) +-- (vim.api.nvim_create_user_command +-- :Sh +-- (fn [cmd] +-- (local thunk #(qfjob [:zshcmd cmd.args] nil)) +-- (set last_job_thunk thunk) +-- (thunk)) +-- {:nargs :* :bang true :complete :shellcmd}) +-- (vim.api.nvim_create_user_command +-- :Recompile +-- (fn [] +-- (if (= nil last_job_state) +-- (vim.notify "nothing to recompile") +-- (if (not (last_job_state:is_closing)) +-- (vim.notify "Last job not finished") +-- (last_job_thunk)))) +-- {:bang true}) +-- (vim.api.nvim_create_user_command +-- :Stop +-- (fn [] +-- (if (not= nil last_job_state) +-- (do +-- (last_job_state:kill) +-- (vim.notify "killed job")) +-- (vim.notify "nothing to do"))) +-- {:bang true}) +-- (vim.api.nvim_create_user_command +-- :Args +-- (fn [obj] +-- (if (not= 0 (length obj.fargs)) +-- (do +-- (local thunk #(qfjob [:sh :-c obj.args] (vim.fn.argv))) +-- (set last_job_thunk thunk) +-- (thunk)))) +-- {:nargs :* :bang true :complete :shellcmd}) +-- +-- +-- +-- (fn browse_git_remote +-- [data] +-- (P data) +-- (local +-- {: commit +-- : git_dir +-- : line1 +-- : line2 +-- : path +-- : remote +-- : remote_name +-- : repo +-- : type } data) +-- +-- (local +-- oilpath +-- (case (vim.fn.bufname "%") +-- (where oilbuf (vim.startswith oilbuf "oil://")) +-- (do +-- (local d (.. "oil://" (vim.fs.dirname git_dir) "/")) +-- (oilbuf:sub (+ 1 (d:len)) (oilbuf:len))) +-- _ +-- "")) +-- +-- (local [home repo] +-- (case remote +-- (where s (vim.startswith s "git@")) +-- (do +-- (or +-- (case [(s:match "(git@)([^:]+):(.*)(%.git)")] +-- ["git@" home repo ".git"] +-- [home repo]) +-- (case [(s:match "(git@)([^:]+):.*/(.*)/(.*)/(.*)")] +-- ["git@" home org project repo] +-- [(home:gsub "ssh%." "") [(.. org "/" project) repo]]))))) +-- +-- (case [home repo] +-- (where ["bitbucket.org" repo]) +-- (do +-- (case [path type] +-- ["" "tree"] +-- (.. "https://" home "/" repo "/src/" commit "/" (or oilpath path "")) +-- [path "blob"] +-- (.. "https://" home "/" repo "/src/" commit "/" path) +-- [path "commit"] +-- (.. "https://" home "/" repo "/commits/" commit) +-- [path "ref"] +-- (.. "https://" home "/" repo "/commits/" commit))) +-- (where ["dev.azure.com" [org repo]]) +-- (do +-- (case [path type] +-- ["" "tree"] +-- (.. "https://" home "/" org "/_git/" repo "?version=GB" commit "&path=/" (or oilpath path "")) +-- [path "blob"] +-- (.. "https://" home "/" org "/_git/" repo "?version=GB" commit "&path=/" path) +-- [path "commit"] +-- (.. "https://" home "/" org "/_git/" repo "/commit/" commit) +-- [path "ref"] +-- (.. "https://" home "/" org "/_git/" repo "/commit/" commit))) +-- (where ["gitlab.com" repo]) +-- (do +-- (case [path type] +-- ["" "tree"] +-- (.. "https://" home "/" repo "/-/tree/" commit "/" (or oilpath "")) +-- [path "commit"] +-- (.. "https://" home "/" repo "/-/commit/" commit) +-- [path "ref"] +-- (.. "https://" home "/" repo "/-/commit/" commit) +-- [path "blob"] +-- (.. "https://" home "/" repo "/-/blob/" commit "/" path))) +-- (where ["github.com" repo]) +-- (do +-- (case [path type] +-- ["" "tree"] +-- (.. "https://" home "/" repo "/tree/" commit "/" (or oilpath "")) +-- [path "commit"] +-- (.. "https://" home "/" repo "/commit/" commit) +-- [path "ref"] +-- (.. "https://" home "/" repo "/commit/" commit) +-- [path "blob"] +-- (.. "https://" home "/" repo "/blob/" commit "/" path))))) +-- +-- (vim.api.nvim_create_user_command +-- :Browse +-- (fn [{: args}] (vim.system ["xdg-open" args] {} (fn []))) +-- {:nargs 1}) +-- +-- (set vim.g.fugitive_browse_handlers +-- [browse_git_remote]) + +require("my.settings") +require("my.events") +require("my.packages") + diff --git a/mut/neovim/lua/my/lsp.lua b/mut/neovim/lua/my/lsp.lua new file mode 100644 index 0000000..ff09277 --- /dev/null +++ b/mut/neovim/lua/my/lsp.lua @@ -0,0 +1,92 @@ +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 = {} + +-- (fn map-to-capabilities [{: client : buf}] +-- (fn use [cpb] +-- (match cpb +-- +-- (each [cpb enabled? (pairs client.server_capabilities)] +-- (if enabled? +-- (use cpb))) +-- {: client : buf}) + +-- (fn register-handlers [{: client : buf}] +-- (tset (. client :handlers) :textDocument/publishDiagnostics +-- (vim.lsp.with +-- (fn [_ result ctx config] +-- (vim.lsp.diagnostic.on_publish_diagnostics _ result ctx +-- config) +-- (vim.diagnostic.setloclist {:open false})) +-- {:virtual_text false +-- :underline true +-- :update_in_insert false +-- :severity_sort true})) +-- {: client : buf}) + +-- (var format-on-save true) +-- (fn toggle-format-on-save [] +-- (set format-on-save (not format-on-save))) +-- (vim.api.nvim_create_user_command :LspToggleOnSave toggle-format-on-save {:nargs 1 :complete (fn [] [:format])}) + +-- (fn events [{: client : buf}] +-- (match client.server_capabilities +-- {:documentFormattingProvider true} +-- (vim.api.nvim_create_autocmd +-- :BufWritePre +-- {:group +-- (vim.api.nvim_create_augroup :format-events {:clear true}) +-- :buffer buf +-- :callback #(if format-on-save (vim.lsp.buf.format))}))) + +M.attach = function (ev) + vim.iter(ev.client.server_capabilities) + :each(function(c) + local fn = capability_map[c] + if fn then fn() end + end) +end + +-- (fn attach [cb] +-- (-> cb +-- (register-handlers) +-- (map-to-capabilities) +-- (events))) +-- (fn lsp-attach-event [ev] +-- (local client (vim.lsp.get_client_by_id ev.data.client_id)) +-- (local buf ev.buf) +-- (attach {: client : buf})) + -- {: attach : lsp-attach-event} +return M diff --git a/mut/neovim/lua/my/packages/cmp.lua b/mut/neovim/lua/my/packages/cmp.lua new file mode 100644 index 0000000..6a22d73 --- /dev/null +++ b/mut/neovim/lua/my/packages/cmp.lua @@ -0,0 +1,138 @@ +local cmp = require("cmp") +local cmp_types = require("cmp.types") +local luasnip = require("luasnip") + +vim.keymap.set("n", "<leader>xf", + function() + local fname = vim.fn.fnamemodify(vim.fn.bufname(vim.api.nvim_get_current_buf()), ":p:h") + vim.api.nvim_feedkeys(":e " .. fname, "c", false) + vim.defer_fn(function() + vim.api.nvim_feedkeys("/", "c", false) + end, 10) + end) + +function snip(args) + luasnip.lsp_expand(args.body) +end + +function has_words_before() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + local word = unpack(vim.api.nvim_buf_get_lines(0, line-1, line, true)) + local before = word:sub(col, col) + local is_string = before:match("%s") + return (not (col == 0)) and is_string +end + +function in_edit_mode(line) + return line:match("^.* %.?.*$") or line:match("^ed?i?t? .*$") +end + +function endswith(line, char) + return line:match(".*" .. char .. "$") +end + +function replace_tail(line) + local result, n = line:gsub("(.*/)[^/]*/$","%1") + if n then + return result + else + return line + end +end + +cmp.setup({ + experimental={ghost_text= true}, + snippet={expand="snip"}, + preselect=cmp.PreselectMode.None, + sources=cmp.config.sources({ + {name= "nvim_lsp"}, + {name= "path"}, + {name= "luasnip"} + }), + mapping={ + ["<Tab>"]=cmp.mapping( + function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, {"i", "s"}), + ["<S-Tab>"]=cmp.mapping( + function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump (1) + else + fallback() + end + end, { "i", "s" }), + ["<C-b>"]=cmp.mapping.scroll_docs(-4), + [ "<C-f>" ]= cmp.mapping.scroll_docs(4), + [ "<C-j>" ]= cmp.mapping.complete(), + [ "<CR>" ]= cmp.mapping.confirm({ + behavior=cmp.ConfirmBehavior.Insert, + select=true}), + }, +}) + +-- This tries to emulate somewhat ido mode to find files +-- todo sorting based on least recently used +cmp.setup.cmdline(":", +{enabled=function() + local val = in_edit_mode(vim.fn.getcmdline()) + if not val then cmp.close() end + return val +end, +sources=cmp.config.sources({ {name="path"} }), +completion={completeopt="menu,menuone,noinsert"}, +mapping={ + ["<C-n>"]=cmp.mapping( + function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + cmp.complete() + end + end, { "i", "c" }), + ["<C-p>"]=cmp.mapping( + function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + cmp.complete() + end + end, { "i", "c" }), + ["<BS>"]=cmp.mapping( + function(fallback) + local line = vim.fn.getcmdline() + if not endswith(line, "/") then + fallback() + else + vim.fn.setcmdline(replace_tail(line)) + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-g><BS>", true, false, true), false) + vim.defer_fn(cmp.complete, 10) + end + end, { "i", "c" }), + ["<CR>"]=cmp.mapping( + function(fallback) + local entry = cmp.get_selected_entry() + local line = vim.fn.getcmdline() + if entry and (not in_edit_mode(line)) then + vim.schedule(fallback) + else + cmp.confirm {select=true, behavior=cmp.ConfirmBehavior.Replace} + if entry and entry.completion_item.label:match("%.*/$") then + vim.defer_fn(cmp.complete, 10) + else + vim.schedule(fallback) + end + end + end, { "i", "c"}) + } +}) diff --git a/mut/neovim/lua/my/packages/dap.lua b/mut/neovim/lua/my/packages/dap.lua new file mode 100644 index 0000000..c9240f9 --- /dev/null +++ b/mut/neovim/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/mut/neovim/lua/my/packages/go.lua b/mut/neovim/lua/my/packages/go.lua new file mode 100644 index 0000000..372d94b --- /dev/null +++ b/mut/neovim/lua/my/packages/go.lua @@ -0,0 +1,34 @@ +local go = require("go") +go.setup { + 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, + luasnip = true, + iferr_vertical_shift = 4, +} diff --git a/mut/neovim/lua/my/packages/init.lua b/mut/neovim/lua/my/packages/init.lua new file mode 100644 index 0000000..082cea4 --- /dev/null +++ b/mut/neovim/lua/my/packages/init.lua @@ -0,0 +1,7 @@ +require("my.packages.oil") +require("my.packages.cmp") +require("my.packages.lint") +require("my.packages.luasnip") +require("my.packages.dap") +require("my.packages.go") +-- require("conf.pkgs.lualine") diff --git a/mut/neovim/lua/my/packages/lint.lua b/mut/neovim/lua/my/packages/lint.lua new file mode 100644 index 0000000..815f9b3 --- /dev/null +++ b/mut/neovim/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/mut/neovim/lua/my/packages/lualine.fnl b/mut/neovim/lua/my/packages/lualine.fnl new file mode 100644 index 0000000..4f57425 --- /dev/null +++ b/mut/neovim/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/mut/neovim/lua/my/packages/luasnip.lua b/mut/neovim/lua/my/packages/luasnip.lua new file mode 100644 index 0000000..eb2f0c6 --- /dev/null +++ b/mut/neovim/lua/my/packages/luasnip.lua @@ -0,0 +1,41 @@ +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() ls.expand_or_jump(1) 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.Printf("), i(1), t(")"), i(2) }) + }) diff --git a/mut/neovim/lua/my/packages/oil.lua b/mut/neovim/lua/my/packages/oil.lua new file mode 100644 index 0000000..49c82c2 --- /dev/null +++ b/mut/neovim/lua/my/packages/oil.lua @@ -0,0 +1,73 @@ +local oil=require("oil") +local fzf=require("fzf-lua") + +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/mut/neovim/lua/my/settings.lua b/mut/neovim/lua/my/settings.lua new file mode 100644 index 0000000..560fa18 --- /dev/null +++ b/mut/neovim/lua/my/settings.lua @@ -0,0 +1,65 @@ +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 |
