diff --git a/nvim/init.lua b/nvim/init.lua index 7e56c58..47336d8 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -7,6 +7,7 @@ require('lualine_config') require('mappings') require('nvim_tree_config') require('teaching') +require('wiki_utils') vim.api.nvim_create_autocmd("FileType", { pattern = "make", command = [[set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab]] }) vim.api.nvim_create_autocmd("FileType", { pattern = "vimwiki", command = [[setlocal shiftwidth=2 softtabstop=2 expandtab]] }) diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 9d58994..375a554 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,38 +1,38 @@ { "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, - "awesomewm-vim-tmux-navigator": { "branch": "master", "commit": "e448723a099a4a702830ffa73791bf5e99b5ef69" }, - "bufferline.nvim": { "branch": "main", "commit": "d24378edc14a675c820a303b4512af3bbc5761e9" }, + "awesomewm-vim-tmux-navigator": { "branch": "master", "commit": "b56319dc9378564d2e1d2123751d6b4a893abfc2" }, + "bufferline.nvim": { "branch": "main", "commit": "6ecd37e0fa8b156099daedd2191130e083fb1490" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp-snippy": { "branch": "master", "commit": "c4dc31232c510cd32d4708701e6f06746d46df90" }, - "diffview.nvim": { "branch": "main", "commit": "7e5a85c186027cab1e825d018f07c350177077fc" }, - "flash.nvim": { "branch": "main", "commit": "967117690bd677cb7b6a87f0bc0077d2c0be3a27" }, - "formatter.nvim": { "branch": "master", "commit": "44c89f09dcc220dc2a9b056e93c3a87c86e79804" }, - "lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" }, + "diffview.nvim": { "branch": "main", "commit": "0437ef8bfdd67156d87140d692840a3c2824fa20" }, + "flash.nvim": { "branch": "main", "commit": "6d76c5dee65181ab55cbdfb0760260e800d643f4" }, + "formatter.nvim": { "branch": "master", "commit": "34dcdfa0c75df667743b2a50dd99c84a557376f0" }, + "lazy.nvim": { "branch": "main", "commit": "2947f104e140e21cc87c55f86c1599fbe26caf0f" }, "lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" }, - "lush.nvim": { "branch": "main", "commit": "a8f0f7b9f837887f13a61d67b40ae26188fe4d62" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "dfdd771b792fbb4bad8e057d72558255695aa1a7" }, - "mason.nvim": { "branch": "main", "commit": "c811fbf09c7642eebb37d6694f1a016a043f6ed3" }, - "neogit": { "branch": "master", "commit": "800a366b9ecd6adf356503bdae93278018bd7a23" }, - "nvim-autopairs": { "branch": "master", "commit": "ae5b41ce880a6d850055e262d6dfebd362bb276e" }, + "lush.nvim": { "branch": "main", "commit": "966aad1accd47fa11fbe2539234f81f678fef2de" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "ddefe5ab051e7ca6a7b374754f0920c44668b54f" }, + "mason.nvim": { "branch": "main", "commit": "cd7835b15f5a4204fc37e0aa739347472121a54c" }, + "neogit": { "branch": "master", "commit": "3f6e559cc9c8a708f8b883ad9987c0a12aa1b3fa" }, + "nvim-autopairs": { "branch": "master", "commit": "748e72c05495a3d30e88a6ef04b21697019a9aa9" }, "nvim-cmp": { "branch": "main", "commit": "5dce1b778b85c717f6614e3f4da45e9f19f54435" }, - "nvim-lspconfig": { "branch": "master", "commit": "a27356f1ef9c11e1f459cc96a3fcac5c265e72d6" }, - "nvim-snippy": { "branch": "master", "commit": "ee3b830787538f259b84867c8971c4284abc4a8d" }, + "nvim-lspconfig": { "branch": "master", "commit": "2b361e043810d5587d9af0787f8ce40da92ec5e9" }, + "nvim-snippy": { "branch": "master", "commit": "5787f088c99c04309a8aa6363fd3ac9a5a26b780" }, "nvim-tree.lua": { "branch": "master", "commit": "59e65d88db177ad1e6a8cffaafd4738420ad20b6" }, - "nvim-treesitter": { "branch": "master", "commit": "d94e1ad9575cc211b5726f09b28ca9454aba22fe" }, - "nvim-web-devicons": { "branch": "master", "commit": "cfc8824cc1db316a276b36517f093baccb8e799a" }, - "oil.nvim": { "branch": "master", "commit": "c12a12c34da2a04465308f410095bcbe47996f0b" }, - "plenary.nvim": { "branch": "master", "commit": "0dbe561ae023f02c2fb772b879e905055b939ce3" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "9bc8237565ded606e6c366a71c64c0af25cd7a50" }, + "nvim-treesitter": { "branch": "master", "commit": "0eb1a0ad1c82e080e77e7b9d7a5e42632cefb543" }, + "nvim-web-devicons": { "branch": "master", "commit": "a1e6268779411048a87f767a27380089362a0ce2" }, + "oil.nvim": { "branch": "master", "commit": "f72b9b2637eec2b3db8255c196aa4bf11231af81" }, + "plenary.nvim": { "branch": "master", "commit": "9ce85b0f7dcfe5358c0be937ad23e456907d410b" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, "telescope-undo.nvim": { "branch": "main", "commit": "3dec002ea3e7952071d26fbb5d01e2038a58a554" }, - "telescope.nvim": { "branch": "master", "commit": "1dfa66b845673effc8771f9ebe511bb36a09f560" }, + "telescope.nvim": { "branch": "master", "commit": "5a747a9587e4bfc4ae086a38cc679fe54f983b69" }, "trim.nvim": { "branch": "master", "commit": "2df124c2c2844d3143091ebd3ae8b49bbe06bc5e" }, - "trouble.nvim": { "branch": "main", "commit": "40aad004f53ae1d1ba91bcc5c29d59f07c5f01d3" }, + "trouble.nvim": { "branch": "main", "commit": "02219b557d4726a789be58c5d6bd6e139c46a9fe" }, "vim-bracketed-paste": { "branch": "master", "commit": "45411da73cc159e4fc2138d930553d247bbfbcdc" }, - "vim-rooter": { "branch": "master", "commit": "4f52ca556a0b9e257bf920658714470ea0320b7a" }, - "vim-snippets": { "branch": "master", "commit": "d37486881a0a771b844a235bc3e025046088690d" }, - "vimtex": { "branch": "master", "commit": "534fd725f2475a9083b032e402c7e73b8a3fc6bb" }, + "vim-rooter": { "branch": "master", "commit": "1353fa47ee3a81083c284e28ff4f7d92655d7c9e" }, + "vim-snippets": { "branch": "master", "commit": "ccc2fa1529d372f7ac16d5eb07a385a72b50e05d" }, + "vimtex": { "branch": "master", "commit": "03c83443108a6984bf90100f6d00ec270b84a339" }, "vimwiki": { "branch": "dev", "commit": "f0fe154ede6b11e3db9b058b930005a056a3d1c6" } } \ No newline at end of file diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 6d13189..b31154d 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -23,7 +23,7 @@ require('lazy').setup({ vim.g.vimwiki_key_mappings = { table_mappings = 0 } vim.g.vimwiki_markdown_link_ext = 1 vim.g.vimwiki_global_ext = 0 - end, ft='markdown' }, + end}, {'stevearc/oil.nvim', opts = { keymaps = { ["g?"] = "actions.show_help", diff --git a/nvim/lua/treesitter_config.lua b/nvim/lua/treesitter_config.lua index 2612b28..99adf10 100644 --- a/nvim/lua/treesitter_config.lua +++ b/nvim/lua/treesitter_config.lua @@ -4,12 +4,12 @@ if not hastreesitter then end treesitter.setup({ - ensure_installed = { "cpp", "c", "lua", "vim", "dockerfile", "python", "java", "cmake", "diff", "gitcommit", "html", "css", "javascript", "json", "markdown", "rust", "sql", "yaml" }, + ensure_installed = { "cpp", "c", "lua", "vim", "dockerfile", "python", "java", "cmake", "diff", "gitcommit", "html", "css", "javascript", "json", "rust", "sql", "yaml" }, auto_install = true, highlight = { enable = true, disable = function(lang, buf) -- Disable if file size is too big - if lang == "ini" then + if lang == "ini" or lang == "markdown" then return true end local max_filesize = 2000 * 1024 -- 2MB diff --git a/nvim/lua/wiki_utils.lua b/nvim/lua/wiki_utils.lua new file mode 100644 index 0000000..0555392 --- /dev/null +++ b/nvim/lua/wiki_utils.lua @@ -0,0 +1,63 @@ +local pickers = require("telescope.pickers") +local actions = require "telescope.actions" +local action_state = require "telescope.actions.state" +local finders = require("telescope.finders") +local conf = require("telescope.config").values + +local wiki_utils = {} + +local root_path = '/home/user/Workspace/DnD/Lumentis Campaign Setting' + +local function get_title(file) + for line in io.lines(file) do + line = string.gsub(line, "#", "") + line = string.gsub(line, "^%s*", "") + line = string.gsub(line, "%s*$", "") + return line + end +end + +-- our picker function: colors +local choose_link = function(opts, titles, links) + opts = opts or {} + pickers.new(opts, { + prompt_title = "Choose a file", + finder = finders.new_table { + results = titles + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr, _) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + -- print(vim.inspect(selection['index'])) + vim.api.nvim_put({ links[selection['index']] }, "", false, true) + end) + return true + end, + }):find() +end + +function wiki_utils.insert_link() + local scan = require("plenary.scandir").scan_dir(root_path) + local titles = {} + local links = {} + for _, v in ipairs(scan) do + if v:match("^.+(%..+)$") == ".md" then + local absolute_filename = string.sub(v, root_path:len()+1, v:len()) + local title = get_title(v) + if title:len() > 0 then + local link = "[" .. title .. "](" .. absolute_filename .. ")" + table.insert(titles, title) + table.insert(links, link) + end + end + end + choose_link(require("telescope.themes").get_dropdown{}, titles, links) +end + +vim.api.nvim_create_user_command("InsertWikiLink", wiki_utils.insert_link, {}) +vim.keymap.set("n", "l", wiki_utils.insert_link, { noremap = true, silent = true }) +vim.keymap.set("i", "l", wiki_utils.insert_link, { noremap = true, silent = true }) + +return wiki_utils