From 79bc79e7f6e0d5ba04c8e428daf515e0f84dba25 Mon Sep 17 00:00:00 2001 From: traxys Date: Sat, 20 Jul 2024 23:27:12 +0200 Subject: [PATCH] neovim: Switch from zk to wiki.vim --- flake.lock | 17 ++++++++++++ flake.nix | 4 +++ neovim/default.nix | 68 +++++++++++++++++----------------------------- neovim/pkg.nix | 5 ++++ 4 files changed, 51 insertions(+), 43 deletions(-) diff --git a/flake.lock b/flake.lock index ccf3b34..3d049e7 100644 --- a/flake.lock +++ b/flake.lock @@ -1391,6 +1391,7 @@ "simulationcraft": "simulationcraft", "treefmt-nix": "treefmt-nix_2", "vim-headerguard": "vim-headerguard", + "wiki.vim": "wiki.vim", "zsh-nix-shell": "zsh-nix-shell" } }, @@ -1860,6 +1861,22 @@ "type": "github" } }, + "wiki.vim": { + "flake": false, + "locked": { + "lastModified": 1720569608, + "narHash": "sha256-5BrfNhD8SPZrObNCFCdrrMPdFpy0Vov+W/ojAxM2v1I=", + "owner": "lervag", + "repo": "wiki.vim", + "rev": "d65fcef243d273787106a1328ff5cad5b1e2a918", + "type": "github" + }, + "original": { + "owner": "lervag", + "repo": "wiki.vim", + "type": "github" + } + }, "zsh-nix-shell": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 1eaf6c9..ecc0d35 100644 --- a/flake.nix +++ b/flake.nix @@ -101,6 +101,10 @@ url = "github:drmikehenry/vim-headerguard"; flake = false; }; + "wiki.vim" = { + url = "github:lervag/wiki.vim"; + flake = false; + }; }; outputs = diff --git a/neovim/default.nix b/neovim/default.nix index 22c7b0c..3e5c41e 100644 --- a/neovim/default.nix +++ b/neovim/default.nix @@ -94,6 +94,7 @@ ]; globals = { + wiki_root = "~/wiki"; neo_tree_remove_legacy_commands = 1; mapleader = " "; }; @@ -144,7 +145,6 @@ { inherit key mode; } // (if builtins.isString action then { inherit action; } else action) ); nm = modeKeys [ "n" ]; - vs = modeKeys [ "v" ]; in helpers.keymaps.mkKeymaps { options.silent = true; } (nm { "ft" = "Neotree"; @@ -170,16 +170,34 @@ desc = "toggle inlay hints"; }; }; - "zn" = "ZkNew { title = vim.fn.input('Title: ') }"; - "zo" = "ZkNotes { sort = { 'modified' } }"; - "zt" = "ZkTags"; - "zf" = "ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }"; "yH" = { action = "Telescope yank_history"; options.desc = "history"; }; + "wS" = { + action = helpers.mkRaw '' + function() + require('telescope.builtin').live_grep({ + cwd = "~/wiki", + glob_pattern = "*.md" + }) + end + ''; + options.desc = "search in wiki"; + }; + "Y" = { + action = helpers.mkRaw '' + function () + vim.go.operatorfunc = "v:lua.osc52_yank_cb"; + local yank = require('vim.ui.clipboard.osc52').copy('+') + end + ''; + options = { + desc = "yank through osc52"; + expr = true; + }; + }; }) - ++ (vs { "zf" = "'<,'>ZkMatch"; }) ++ [ { key = "rn"; @@ -718,11 +736,6 @@ -- null_ls.register(sca2d) ''; - plugins.zk = { - enable = true; - settings.picker = "telescope"; - }; - plugins.which-key.enable = true; plugins.leap.enable = true; @@ -746,38 +759,6 @@ ''; }; - files."ftplugin/markdown.lua" = { - extraConfigLua = '' - if require("zk.util").notebook_root(vim.fn.expand('%:p')) ~= nil then - local function map(...) vim.api.nvim_buf_set_keymap(0, ...) end - local opts = { noremap=true, silent=false } - - -- Open the link under the caret. - map("n", "", "lua vim.lsp.buf.definition()", opts) - - -- Create a new note after asking for its title. - -- This overrides the global `zn` mapping to create the note in the same directory as the current buffer. - map("n", "zn", "ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", opts) - -- Create a new note in the same directory as the current buffer, using the current selection for title. - map("v", "znt", ":'<,'>ZkNewFromTitleSelection { dir = vim.fn.expand('%:p:h') }", opts) - -- Create a new note in the same directory as the current buffer, using the current selection for note content and asking for its title. - map("v", "znc", ":'<,'>ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", opts) - - -- Open notes linking to the current buffer. - map("n", "zb", "ZkBacklinks", opts) - -- Alternative for backlinks using pure LSP and showing the source context. - --map('n', 'zb', 'lua vim.lsp.buf.references()', opts) - -- Open notes linked by the current buffer. - map("n", "zl", "ZkLinks", opts) - - -- Preview a linked note. - map("n", "K", "lua vim.lsp.buf.hover()", opts) - -- Open the code actions for a visual selection. - map("v", "za", ":'<,'>lua vim.lsp.buf.range_code_action()", opts) - end - ''; - }; - extraPackages = with pkgs; [ # sca2d djlint @@ -785,6 +766,7 @@ ]; extraPlugins = with pkgs.vimPlugins; [ + wiki-vim telescope-ui-select-nvim vim-snippets markdown-preview-nvim diff --git a/neovim/pkg.nix b/neovim/pkg.nix index 6155344..d4730dc 100644 --- a/neovim/pkg.nix +++ b/neovim/pkg.nix @@ -27,6 +27,11 @@ src = inputs.vim-headerguard; version = inputs.vim-headerguard.shortRev; }; + wiki-vim = prev.vimUtils.buildVimPlugin { + pname = "wiki.vim"; + src = inputs."wiki.vim"; + version = inputs."wiki.vim".shortRev; + }; } ); }