diff --git a/after/plugin/grapple.lua b/after/plugin/grapple.lua deleted file mode 100644 index bbdd963..0000000 --- a/after/plugin/grapple.lua +++ /dev/null @@ -1,6 +0,0 @@ -local ok, grapple = pcall(require, "grapple") -if not ok then - vim.notify("missing module grapple", vim.log.levels.WARN) - return -end - diff --git a/after/plugin/highlight.vim b/after/plugin/highlight.vim index 169c6a0..5f3e3dd 100644 --- a/after/plugin/highlight.vim +++ b/after/plugin/highlight.vim @@ -9,3 +9,4 @@ " GuiGua selected item (navigator etc ) au BufEnter * hi GuihuaListSelHl gui=underline guibg=bg + diff --git a/after/plugin/remote-lsp.lua b/after/plugin/remote-lsp.lua new file mode 100644 index 0000000..f7e86af --- /dev/null +++ b/after/plugin/remote-lsp.lua @@ -0,0 +1 @@ +-- require('scratch.remote-lsp').setup_lsp_dirhook() diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index a87d62a..472c8c1 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -144,6 +144,7 @@ M.general = { --{{{ -- new buffer ["bb"] = { " enew ", "new buffer" }, + ["bv"] = { " enew ", "new buffer" }, -- new tab [""] = { " tabe ", "new tab" }, @@ -372,12 +373,12 @@ M.general = { --{{{ -- operator pending o = { - ["S"] = { "(leap-forward-to)" }, + ["S"] = { "(leap-forward-to)", opts = { remap = true} }, }, - -- select mode (with completion) + -- select mode (with completion) see after/plugin/mappings.* s = { - [""] = {"i"}, -- delete and go to insert mode + [""] = {"i", "delete then go insert"}, }, -- visual exclusive mode (ignore select) @@ -805,6 +806,24 @@ M.nvterm = { --{{{ end, "new vertical term", }, + + + -- Running commands + ["rf"] = {function() + local nvterm_utils = require('spike.utils.nvterm') + nvterm_utils.run_cmd(nil, { mode = "float" }) + end, "run cmd in floating terminal"}, + + ["rv"] = {function() + local nvterm_utils = require('spike.utils.nvterm') + nvterm_utils.run_cmd(nil, { mode = "vertical" }) + end, "run cmd in floating terminal"}, + + + [""] = {function() + local nvterm_utils = require('spike.utils.nvterm') + nvterm_utils.rerun_last_cmd() + end, "rerun last float term cmd"}, }, } --}}} @@ -864,13 +883,30 @@ M.asyncrun = { --{{{ n = { -- TODO: find new mapping to close quickfix -- ["``"] = { " call asyncrun#quickfix_toggle(8)", "toggle quickfix window" }, - ["m"] = { ":AsyncRun -program=" .. vim.o.makeprg .. "", "make using asyncrun" }, - ["ar"] = { ":AsyncRun ", "custom asyncrun command" }, + -- HELP: + -- adding ! after AsyncRun disables autoscroll + ["m"] = { ":AsyncRun -program=" .. vim.o.makeprg .. "", "make using quickfix asyncrun" }, + ["mf"] = { function() + require('spike.utils.nvterm').run_cmd(vim.o.makeprg, { mode = "float"} ) + end, "run make in a floating terminal" }, + ["rx"] = {function() + vim.ui.input( { prompt="tmux cmd:> " }, function (input) + vim.cmd("AsyncRun -mode=term -pos=tmux " .. input) + end) + end, "custom asyncrun command (tmux)" }, ["pd"] = { " AsyncRun lpr -P PDF_PRINT %", "PDF print file" }, ["pp"] = { " AsyncRun lpr %" }, }, } --}}} +M.overseer = { + plugin = true, + n = { + ["oo"] = {" OverseerOpen ", "open overseer"}, + ["ot"] = {" OverseerToggle ", "open overseer"}, + } +} + M.vim_bookmarks = { --{{{ n = { ["m"] = { " Telescope vim_bookmarks", "show bookmarks" }, @@ -978,21 +1014,55 @@ M.grapple = { require("grapple").tag({ name = input }) end) end, "grapple tag with name" }, + --TODO: keybind for popup select names [",,m"] = { " lua require'grapple'.select({name='mappings'})" }, [",,p"] = { " lua require'grapple'.select({name='plugins'})" }, [",,P"] = { " lua require'grapple'.select({name='Plugins'})" }, } } +local function get_zk_notedirs() + local abs_dirs = vim.fn.system("fd . -t d " .. vim.env['ZK_NOTEBOOK_DIR']) + local note_dirs = {} + for _,v in ipairs(vim.split(abs_dirs, "\n")) do + local ndir = string.gsub(v, vim.env['ZK_NOTEBOOK_DIR'] .. '/', '') + ndir = ndir:gsub("(.*)(/)$", "%1") + if ndir ~= "" then + table.insert(note_dirs,ndir) + end + end + + vim.ui.select(note_dirs, { prompt = "dir:> " }, + function(choice) + if choice then + require("zk.commands").get("ZkNew")({ dir = choice }) + end + end) +end + M.zk = { plugin = true, n = { - ["zn"] = {"ZkNew { title = vim.fn.input('Title: ') }","zk new note"}, - ["zk"] = {"ZkNotes { sort = { 'modified' }}","zk list notes"}, - ["zf"] = {"ZkNotes { sort = { 'modified' }, match = vim.fn.input('Search: ') }","zk notes matching a given query"}, + ["zk"] = {function() + vim.ui.input({ prompt = "note title:"}, function (input) + if input then + require("zk.commands").get("ZkNew")({ title = input}) + end + end) + end, "zk new note"}, + ["zK"] = {get_zk_notedirs, "zk new note, custom dir"}, + ["zo"] = {"ZkNotes { sort = { 'modified' }}","zk list notes"}, + -- ["zf"] = {"ZkNotes { sort = { 'modified' }, match = vim.fn.input('Search: ') }","zk notes matching a given query"}, + ["zf"] = {function() + vim.ui.input({ prompt = "zk match:"}, function (input) + if input then + require("zk.commands").get("ZkNotes")({ sort = { "modified" }, match = input}) + end + end) + end,"zk notes matching a given query"}, ["zl"] = {"ZkLinks","zk links"}, ["zh"] = {"ZkBacklinks","zk backlinks"}, - + -- mappings to lsp commands are in zk.lua config file } } diff --git a/lua/core/options.lua b/lua/core/options.lua index 4cf1698..90ca694 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -66,7 +66,7 @@ opt.iskeyword:remove("-") -- opt.foldexpr="nvim_treesitter#foldexpr()" -- opt.foldminlines = 2 -opt.foldlevelstart = 0 +opt.foldlevelstart = 1 opt.conceallevel=1 -- how to show text with :syn-conceal syntax opt.list = true -- show tabs,trailing spaces and non-breakable spaces diff --git a/lua/custom/plugins/configs/aerial.lua b/lua/custom/plugins/configs/aerial.lua index 17be6b1..8c647fe 100644 --- a/lua/custom/plugins/configs/aerial.lua +++ b/lua/custom/plugins/configs/aerial.lua @@ -133,7 +133,7 @@ local opts = { -- Fold code when you open/collapse symbols in the tree. -- Only works when manage_folds = true - link_tree_to_folds = true, + link_tree_to_folds = false, -- Use symbol tree for folding. Set to true or false to enable/disable -- 'auto' will manage folds if your previous foldmethod was 'manual' diff --git a/lua/custom/plugins/configs/dressing.lua b/lua/custom/plugins/configs/dressing.lua new file mode 100644 index 0000000..d4dd748 --- /dev/null +++ b/lua/custom/plugins/configs/dressing.lua @@ -0,0 +1,169 @@ +local ok, dressing = pcall(require, "dressing") +if not ok then + vim.notify("missing module dressing", vim.log.levels.WARN) + return +end + +local M = {} + +config = { + input = { + -- Set to false to disable the vim.ui.input implementation + enabled = true, + + -- Default prompt string + default_prompt = "Input:", + + -- Can be 'left', 'right', or 'center' + prompt_align = "left", + + -- When true, will close the modal + insert_only = true, + + -- When true, input will start in insert mode. + start_in_insert = true, + + -- These are passed to nvim_open_win + anchor = "SW", + border = "rounded", + -- 'editor' and 'win' will default to being centered + relative = "cursor", + + -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%) + prefer_width = 40, + width = nil, + -- min_width and max_width can be a list of mixed types. + -- min_width = {20, 0.2} means "the greater of 20 columns or 20% of total" + max_width = { 140, 0.9 }, + min_width = { 20, 0.2 }, + + -- Window transparency (0-100) + winblend = 10, + -- Change default highlight groups (see :help winhl) + winhighlight = "", + + -- Set to `false` to disable + mappings = { + n = { + [""] = "Close", + [""] = "Confirm", + }, + i = { + [""] = "Close", + [""] = "Confirm", + [""] = "HistoryPrev", + [""] = "HistoryNext", + }, + }, + + override = function(conf) + -- This is the config that will be passed to nvim_open_win. + -- Change values here to customize the layout + return conf + end, + + -- see :help dressing_get_config + get_config = nil, + }, + select = { + -- Set to false to disable the vim.ui.select implementation + enabled = true, + + -- Priority list of preferred vim.select implementations + backend = { "fzf_lua", "telescope", "fzf", "builtin", "nui" }, + + -- Trim trailing `:` from prompt + trim_prompt = true, + + -- Options for telescope selector + -- These are passed into the telescope picker directly. Can be used like: + -- telescope = require('telescope.themes').get_ivy({...}) + telescope = nil, + + -- Options for fzf selector + fzf = { + window = { + width = 0.5, + height = 0.4, + }, + }, + + -- Options for fzf_lua selector + fzf_lua = { + winopts = { + width = 0.5, + height = 0.6, + }, + }, + + -- Options for nui Menu + nui = { + position = "50%", + size = nil, + relative = "editor", + border = { + style = "rounded", + }, + buf_options = { + swapfile = false, + filetype = "DressingSelect", + }, + win_options = { + winblend = 10, + }, + max_width = 80, + max_height = 40, + min_width = 40, + min_height = 10, + }, + + -- Options for built-in selector + builtin = { + -- These are passed to nvim_open_win + anchor = "NW", + border = "rounded", + -- 'editor' and 'win' will default to being centered + relative = "editor", + + -- Window transparency (0-100) + winblend = 10, + -- Change default highlight groups (see :help winhl) + winhighlight = "", + + -- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%) + -- the min_ and max_ options can be a list of mixed types. + -- max_width = {140, 0.8} means "the lesser of 140 columns or 80% of total" + width = nil, + max_width = { 140, 0.8 }, + min_width = { 40, 0.2 }, + height = nil, + max_height = 0.9, + min_height = { 10, 0.2 }, + + -- Set to `false` to disable + mappings = { + [""] = "Close", + [""] = "Close", + [""] = "Confirm", + }, + + override = function(conf) + -- This is the config that will be passed to nvim_open_win. + -- Change values here to customize the layout + return conf + end, + }, + + -- Used to override format_item. See :help dressing-format + format_item_override = {}, + + -- see :help dressing_get_config + get_config = nil, + }, +} + +M.setup = function() + dressing.setup(config) +end + +return M diff --git a/lua/custom/plugins/configs/fzflua.lua b/lua/custom/plugins/configs/fzflua.lua index 01bf79b..79eccd6 100644 --- a/lua/custom/plugins/configs/fzflua.lua +++ b/lua/custom/plugins/configs/fzflua.lua @@ -4,8 +4,6 @@ if not present then return end -fzf.register_ui_select() - local options = { keymap = { diff --git a/lua/custom/plugins/configs/navigator.lua b/lua/custom/plugins/configs/navigator.lua index 87a1c81..2dbdaef 100644 --- a/lua/custom/plugins/configs/navigator.lua +++ b/lua/custom/plugins/configs/navigator.lua @@ -151,6 +151,7 @@ local config = { -- disable auto start of lsp per language -- set global default on lspconfig (see lspconfig doc) gopls = { + -- cmd = {"socat", "-" ,"tcp:localhost:4444"}, -- on_attach = require("spike.lsp.go").custom_attach, on_attach = require("spike.lsp.go").gopls_onattach, settings = { diff --git a/lua/custom/plugins/configs/overseer.lua b/lua/custom/plugins/configs/overseer.lua new file mode 100644 index 0000000..4817dff --- /dev/null +++ b/lua/custom/plugins/configs/overseer.lua @@ -0,0 +1,17 @@ +local ok, overseer = pcall(require, 'overseer') +if not ok then + vim.notify("missing module overseer", vim.log.levels.WARN) + return +end + +opts = { + +} + +local M = {} + +M.setup = function() + require("overseer").setup(opts) +end + +return M diff --git a/lua/custom/plugins/configs/zk.lua b/lua/custom/plugins/configs/zk.lua index 3460bb3..3e10934 100644 --- a/lua/custom/plugins/configs/zk.lua +++ b/lua/custom/plugins/configs/zk.lua @@ -12,6 +12,10 @@ local opts = { name = "zk", -- on_attach = ... -- etc, see `:h vim.lsp.start_client()` + on_attach = function(client, bufnr) + vim.keymap.set("n", "K", " lua vim.lsp.buf.hover()", { desc = "zk lsp hover"}) + vim.keymap.set("v", "za", ":'<,'> vim.lsp.buf.range_code_action()", { desc = { "zk range code action"}}) + end }, -- automatically attach buffers in a zk notebook that match the given filetypes diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index f592a0a..9b8be93 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -219,7 +219,12 @@ return { }, -- }}} -- User Interface / UX - -- + ["stevearc/dressing.nvim"] = { + config = function() + require("custom.plugins.configs.dressing").setup() + end + }, + -- allows to preview commands after they are registerd by plugin -- the current registerd norm command works by first selecting a visual selection -- then doing the changes, it's an enhanced multi cursor @@ -302,6 +307,7 @@ return { }, -- }}} ["cbochs/grapple.nvim"] = { + commit = "50b8271", setup = function() require("core.utils").load_mappings "grapple" end, @@ -311,6 +317,8 @@ return { -- Leave empty to use the default configuration -- Please see the Configuration section below for more information save_path = vim.fn.stdpath("data") .. "/" .. "grapple.json", + scope = "global", + log_level = "debug", }) end @@ -347,7 +355,17 @@ return { }, -- }}} -- TODO: asynctsks vs overseer: task runner and job management - -- ["stevarc/overseer.nvim"] = {}, + -- NOTE: asynctasks uses AsyncRun !! + ["stevearc/overseer.nvim"] = { + cmd = {"Overseer*"}, + setup = function() + require 'core.utils'.load_mappings 'overseer' + end, + config = function() + require("custom.plugins.configs.overseer").setup() + end, + }, + -- Git ["lewis6991/gitsigns.nvim"] = { @@ -399,6 +417,7 @@ return { }, -- }}}}}} + -- options are defined in plugin/globals.vim ["MattesGroeger/vim-bookmarks"] = { -- {{{ config = function() require("core.utils").load_mappings "vim_bookmarks" diff --git a/lua/spike/lsp/go.lua b/lua/spike/lsp/go.lua index 1cb1c6c..ecad6f4 100644 --- a/lua/spike/lsp/go.lua +++ b/lua/spike/lsp/go.lua @@ -16,15 +16,16 @@ function M.gopls_onattach(client, bufnr) return end - + + -- Auto import on save -- autocmd({"BufWritePre", "InsertLeave"}, { - autocmd({"BufWritePre"}, { - group = augroup(augroupname, {clear = true}), - buffer = bufnr, - callback = function() - goformat.goimport() - end - }) + -- autocmd({"BufWritePre"}, { + -- group = augroup(augroupname, {clear = true}), + -- buffer = bufnr, + -- callback = function() + -- goformat.goimport() + -- end + -- }) require("core.utils").load_mappings "golang" diff --git a/lua/spike/utils/nvterm.lua b/lua/spike/utils/nvterm.lua new file mode 100644 index 0000000..336d360 --- /dev/null +++ b/lua/spike/utils/nvterm.lua @@ -0,0 +1,38 @@ +local ok, terminal = pcall(require, 'nvterm.terminal') +if not ok then + vim.notify("missing module nvterm.terminal", vim.log.levels.WARN) + return +end +local M = {} + +M.last_cmds = {} + +---run cmd using builtin terminal +---@alias mode "vertical" | "horizontal" | "float" +---@param input string command to be run in term +---@param opts? { mode: mode } options +M.run_cmd = function(input, opts) + opts = opts or { mode = "vertical" } + + + if input then + table.insert(M.last_cmds, 1, input) + terminal.send(input, opts.mode) + return + end + + + vim.ui.input({ prompt = "float term cmd:> "}, function(linput) + table.insert(M.last_cmds, 1, linput) + terminal.send(linput, opts.mode) + end) +end + +M.rerun_last_cmd = function() + P(M.last_cmds) + if #M.last_cmds > 0 then terminal.send(M.last_cmds[1]) end +end + + + +return M diff --git a/mysnippets/go.lua b/mysnippets/go.lua index 35f995f..0ce7dbe 100644 --- a/mysnippets/go.lua +++ b/mysnippets/go.lua @@ -4,4 +4,34 @@ return { -- s("testgo", { -- t"Hello go snippet" -- }) + + -- defer + s("def", fmt([[ + defer func(){{ + {} + }}() + + ]], + { + i(0) + }) + + ), + + -- defer and handle error from some call + s({trig = "defe", dscr = "defer with error"}, fmt([[ + defer func(){{ + err := {} + if err != nil {{ + {} + }} + }}() + + ]], + { + i(1), + i(0) + }) + + ), } diff --git a/mysnippets/lua.lua b/mysnippets/lua.lua index b237e57..7e5e891 100644 --- a/mysnippets/lua.lua +++ b/mysnippets/lua.lua @@ -13,13 +13,15 @@ return M -- repeat nodes -- TODO: split dot and pull last name - s("req", fmt("local {} = require('{}')", { + -- local require + s("lreq", fmt("local {} = require('{}')", { i(1, "default"), rep(1) }) ), + -- if require s("ifreq", fmt([[ - local ok, {} = pcall(require, "{}") + local ok, {} = pcall(require, '{}') if not ok then vim.notify("missing module {}", vim.log.levels.WARN) return @@ -34,4 +36,17 @@ return M ), + -- add packer plugin + s({ trig = "plug", dscr = "add packer plugin"}, fmt([[ + ["{}"] = {{ + config = function() + require("custom.plugins.configs.{}").{} + end, + }}, + ]], { + i(1), + i(2), + i(0) + })) + } diff --git a/notes/Tips.md b/notes/Tips.md index dbfe277..c16c3b2 100644 --- a/notes/Tips.md +++ b/notes/Tips.md @@ -1,4 +1,4 @@ - +- remember live command - !{motion}{filter} filter text lines through ext program - !!{filter} filter lines through ext program - review using C-x C-l with context aware situation