commit 0ec94b8eec50963c635eee4669cd7939f5e7dcb4
parent fd05742c52ef23178daee716b0eb0d4f1788f10e
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Sun,  9 Jan 2022 22:10:17 +0100

Use telescope picker for vimwiki shortcut

Diffstat:
M.config/nvim/init.vim | 2+-
M.config/nvim/lua/plugins.lua | 1+
A.config/nvim/lua/telescope-pickers.lua | 27+++++++++++++++++++++++++++
D.config/nvim/templates/vimwiki.md | 14--------------
4 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim @@ -192,7 +192,7 @@ set laststatus=2 " activate status line nnoremap <Leader>ts :-1read $XDG_CONFIG_HOME/nvim/templates/shebang.sh<CR>:w<CR>:e<CR> nnoremap <Leader>tp :-1read $XDG_CONFIG_HOME/nvim/templates/shebang.py<CR>:w<CR>:e<CR> -nnoremap <Leader>tw :-1read $XDG_CONFIG_HOME/nvim/templates/vimwiki.md<CR> +nnoremap <Leader>tw :lua telescope_vimwiki_categories_picker()<CR> " /templates }}} diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua @@ -32,6 +32,7 @@ do -- telescope vim.cmd "nnoremap <Leader>g :Telescope git_files<CR>" vim.cmd "nnoremap <Leader>b :Telescope buffers<CR>" vim.cmd "nnoremap <Leader>h :Telescope help_tags<CR>" + require("telescope-pickers") end diff --git a/.config/nvim/lua/telescope-pickers.lua b/.config/nvim/lua/telescope-pickers.lua @@ -0,0 +1,27 @@ +local status_ok, pickers = pcall(require, "telescope.pickers") +if not status_ok then return end -- if telescope not installed, return + +local finders = require("telescope.finders") +local conf = require("telescope.config").values +local actions = require("telescope.actions") +local action_state = require("telescope.actions.state") + + +telescope_vimwiki_categories_picker = function(opts) + opts = opts or {} + pickers.new(opts, { + prompt_title = "VimWiki Categories", + finder = finders.new_table { + results = vim.g.vw_categories + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr, map) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vim.api.nvim_put({ "<!-- category: " .. selection[1] .. " -->", "" }, "", false, true) + end) + return true + end, + }):find() +end diff --git a/.config/nvim/templates/vimwiki.md b/.config/nvim/templates/vimwiki.md @@ -1,14 +0,0 @@ -<!-- category: -Arrel -Notes -Temporal -Receptes -Blog -Projectes -Tecnologia -Programari -Altres -Arxiu -Sense\ categoria ---> -#