From 84861698bca25d6f181dbba74ded734a7208f75e Mon Sep 17 00:00:00 2001 From: Jannik Buhr Date: Wed, 3 Jan 2024 14:30:37 +0100 Subject: [PATCH] feat: new image paste plugin --- lua/config/keymap.lua | 396 +++++++++++++++++++++-------------------- lua/plugins/quarto.lua | 34 ++-- 2 files changed, 218 insertions(+), 212 deletions(-) diff --git a/lua/config/keymap.lua b/lua/config/keymap.lua index 92db26e..c14ba5d 100644 --- a/lua/config/keymap.lua +++ b/lua/config/keymap.lua @@ -1,29 +1,29 @@ local wk = require("which-key") P = function(x) - print(vim.inspect(x)) - return x + print(vim.inspect(x)) + return x end RELOAD = function(...) - return require("plenary.reload").reload_module(...) + return require("plenary.reload").reload_module(...) end R = function(name) - RELOAD(name) - return require(name) + RELOAD(name) + return require(name) end local nmap = function(key, effect) - vim.keymap.set("n", key, effect, { silent = true, noremap = true }) + vim.keymap.set("n", key, effect, { silent = true, noremap = true }) end local vmap = function(key, effect) - vim.keymap.set("v", key, effect, { silent = true, noremap = true }) + vim.keymap.set("v", key, effect, { silent = true, noremap = true }) end local imap = function(key, effect) - vim.keymap.set("i", key, effect, { silent = true, noremap = true }) + vim.keymap.set("i", key, effect, { silent = true, noremap = true }) end -- save with ctrl+s @@ -93,225 +93,229 @@ nmap("H", "tabprevious") nmap("L", "tabnext") local function toggle_light_dark_theme() - if vim.o.background == "light" then - vim.o.background = "dark" - vim.cmd([[Catppuccin mocha]]) - else - vim.o.background = "light" - vim.cmd([[Catppuccin latte]]) - end + if vim.o.background == "light" then + vim.o.background = "dark" + vim.cmd([[Catppuccin mocha]]) + else + vim.o.background = "light" + vim.cmd([[Catppuccin latte]]) + end end --show kepbindings with whichkey --add your own here if you want them to --show up in the popup as well wk.register({ - c = { - name = "code", - c = { ":SlimeConfig", "slime config" }, - n = { ":vsplit term://$SHELL", "new terminal" }, - r = { ":vsplit term://R", "new R terminal" }, - p = { ":vsplit term://python", "new python terminal" }, - i = { ":vsplit term://ipython", "new ipython terminal" }, - j = { ":vsplit term://julia", "new julia terminal" }, - }, - ["coo"] = { "o# %%", "new code chunk below" }, - ["cOo"] = { "O# %%", "new code chunk above" }, - ["cob"] = { "o```{bash}```O", "bash code chunk" }, - ["cor"] = { "o```{r}```O", "r code chunk" }, - ["cop"] = { "o```{python}```O", "python code chunk" }, - ["coj"] = { "o```{julia}```O", "julia code chunk" }, - ["col"] = { "o```{julia}```O", "julia code chunk" }, - v = { - name = "vim", - t = { toggle_light_dark_theme, "switch theme" }, - c = { ":Telescope colorscheme", "colortheme" }, - l = { ":Lazy", "Lazy" }, - m = { ":Mason", "Mason" }, - s = { ":e $MYVIMRC | :cd %:p:h | split . | wincmd k", "Settings" }, - h = { ':execute "h " . expand("")', "help" }, - }, - l = { - name = "language/lsp", - r = { "Telescope lsp_references", "references" }, - R = { "rename" }, - D = { vim.lsp.buf.type_definition, "type definition" }, - a = { vim.lsp.buf.code_action, "coda action" }, - e = { vim.diagnostic.open_float, "diagnostics" }, - d = { - name = "diagnostics", - d = { vim.diagnostic.disable, "disable" }, - e = { vim.diagnostic.enable, "enable" }, - }, - g = { ":Neogen", "neogen docstring" }, - s = { ":ls!", "list all buffers" }, - }, - o = { - name = "otter & code", - a = { require("otter").dev_setup, "otter activate" }, - ["o"] = { "o# %%", "new code chunk below" }, - ["O"] = { "O# %%", "new code chunk above" }, - ["b"] = { "o```{bash}```O", "bash code chunk" }, - ["r"] = { "o```{r}```O", "r code chunk" }, - ["p"] = { "o```{python}```O", "python code chunk" }, - ["j"] = { "o```{julia}```O", "julia code chunk" }, - ["l"] = { "o```{julia}```O", "julia code chunk" }, - }, - q = { - name = "quarto", - a = { ":QuartoActivate", "activate" }, - p = { ":lua require'quarto'.quartoPreview()", "preview" }, - q = { ":lua require'quarto'.quartoClosePreview()", "close" }, - h = { ":QuartoHelp ", "help" }, - r = { - name = "run", - r = { ":QuartoSendAbove", "to cursor" }, - a = { ":QuartoSendAll", "all" }, - }, - e = { ":lua require'otter'.export()", "export" }, - E = { ":lua require'otter'.export(true)", "export overwrite" }, - }, - f = { - name = "find (telescope)", - f = { "Telescope find_files", "files" }, - h = { "Telescope help_tags", "help" }, - k = { "Telescope keymaps", "keymaps" }, - r = { "Telescope lsp_references", "references" }, - g = { "Telescope live_grep", "grep" }, - b = { "Telescope current_buffer_fuzzy_find", "fuzzy" }, - m = { "Telescope marks", "marks" }, - M = { "Telescope man_pages", "man pages" }, - c = { "Telescope git_commits", "git commits" }, - s = { "Telescope lsp_document_symbols", "symbols" }, - d = { "Telescope buffers", "buffers" }, - q = { "Telescope quickfix", "quickfix" }, - l = { "Telescope loclist", "loclist" }, - j = { "Telescope jumplist", "marks" }, - p = { "project" }, - }, - h = { - name = "help/debug/conceal", - c = { - name = "conceal", - h = { ":set conceallevel=1", "hide/conceal" }, - s = { ":set conceallevel=0", "show/unconceal" }, - }, - t = { - name = "treesitter", - t = { vim.treesitter.inspect_tree, "show tree" }, - c = { ":=vim.treesitter.get_captures_at_cursor()", "show capture" }, - n = { ":=vim.treesitter.get_node():type()", "show node" }, - }, - }, - s = { - name = "spellcheck", - s = { "Telescope spell_suggest", "spelling" }, - ["/"] = { "setlocal spell!", "spellcheck" }, - n = { "]s", "next" }, - p = { "[s", "previous" }, - g = { "zg", "good" }, - r = { "zg", "rigth" }, - w = { "zw", "wrong" }, - b = { "zw", "bad" }, - ["?"] = { "Telescope spell_suggest", "suggest" }, - }, - g = { - name = "git", - c = { ":GitConflictRefresh", "conflict" }, - g = { ":Neogit", "neogit" }, - s = { ":Gitsigns", "gitsigns" }, - pl = { ":Octo pr list", "gh pr list" }, - pr = { ":Octo review start", "gh pr review" }, - wc = { ":lua require('telescope').extensions.git_worktree.create_git_worktree()", "worktree create" }, - ws = { ":lua require('telescope').extensions.git_worktree.git_worktrees()", "worktree switch" }, - d = { - name = "diff", - o = { ":DiffviewOpen", "open" }, - c = { ":DiffviewClose", "close" }, - }, - b = { - name = "blame", - b = { ":GitBlameToggle", "toggle" }, - o = { ":GitBlameOpenCommitURL", "open" }, - c = { ":GitBlameCopyCommitURL", "copy" }, - }, - }, - w = { - name = "write", - w = { ":w", "write" }, - }, - x = { - name = "execute", - x = { ":w:source %", "file" }, - }, + c = { + name = "code", + c = { ":SlimeConfig", "slime config" }, + n = { ":vsplit term://$SHELL", "new terminal" }, + r = { ":vsplit term://R", "new R terminal" }, + p = { ":vsplit term://python", "new python terminal" }, + i = { ":vsplit term://ipython", "new ipython terminal" }, + j = { ":vsplit term://julia", "new julia terminal" }, + ["oo"] = { "o# %%", "new code chunk below" }, + ["Oo"] = { "O# %%", "new code chunk above" }, + ["ob"] = { "o```{bash}```O", "bash code chunk" }, + ["or"] = { "o```{r}```O", "r code chunk" }, + ["op"] = { "o```{python}```O", "python code chunk" }, + ["oj"] = { "o```{julia}```O", "julia code chunk" }, + ["ol"] = { "o```{julia}```O", "julia code chunk" }, + }, + i = { + name = "insert", + i = { ":PasteImage", "image from clipboard" }, + }, + v = { + name = "vim", + t = { toggle_light_dark_theme, "switch theme" }, + c = { ":Telescope colorscheme", "colortheme" }, + l = { ":Lazy", "Lazy" }, + m = { ":Mason", "Mason" }, + s = { ":e $MYVIMRC | :cd %:p:h | split . | wincmd k", "Settings" }, + h = { ':execute "h " . expand("")', "help" }, + }, + l = { + name = "language/lsp", + r = { "Telescope lsp_references", "references" }, + R = { "rename" }, + D = { vim.lsp.buf.type_definition, "type definition" }, + a = { vim.lsp.buf.code_action, "coda action" }, + e = { vim.diagnostic.open_float, "diagnostics" }, + d = { + name = "diagnostics", + d = { vim.diagnostic.disable, "disable" }, + e = { vim.diagnostic.enable, "enable" }, + }, + g = { ":Neogen", "neogen docstring" }, + s = { ":ls!", "list all buffers" }, + }, + o = { + name = "otter & code", + a = { require("otter").dev_setup, "otter activate" }, + ["o"] = { "o# %%", "new code chunk below" }, + ["O"] = { "O# %%", "new code chunk above" }, + ["b"] = { "o```{bash}```O", "bash code chunk" }, + ["r"] = { "o```{r}```O", "r code chunk" }, + ["p"] = { "o```{python}```O", "python code chunk" }, + ["j"] = { "o```{julia}```O", "julia code chunk" }, + ["l"] = { "o```{julia}```O", "julia code chunk" }, + }, + q = { + name = "quarto", + a = { ":QuartoActivate", "activate" }, + p = { ":lua require'quarto'.quartoPreview()", "preview" }, + q = { ":lua require'quarto'.quartoClosePreview()", "close" }, + h = { ":QuartoHelp ", "help" }, + r = { + name = "run", + r = { ":QuartoSendAbove", "to cursor" }, + a = { ":QuartoSendAll", "all" }, + }, + e = { ":lua require'otter'.export()", "export" }, + E = { ":lua require'otter'.export(true)", "export overwrite" }, + }, + f = { + name = "find (telescope)", + f = { "Telescope find_files", "files" }, + h = { "Telescope help_tags", "help" }, + k = { "Telescope keymaps", "keymaps" }, + r = { "Telescope lsp_references", "references" }, + g = { "Telescope live_grep", "grep" }, + b = { "Telescope current_buffer_fuzzy_find", "fuzzy" }, + m = { "Telescope marks", "marks" }, + M = { "Telescope man_pages", "man pages" }, + c = { "Telescope git_commits", "git commits" }, + s = { "Telescope lsp_document_symbols", "symbols" }, + d = { "Telescope buffers", "buffers" }, + q = { "Telescope quickfix", "quickfix" }, + l = { "Telescope loclist", "loclist" }, + j = { "Telescope jumplist", "marks" }, + p = { "project" }, + }, + h = { + name = "help/debug/conceal", + c = { + name = "conceal", + h = { ":set conceallevel=1", "hide/conceal" }, + s = { ":set conceallevel=0", "show/unconceal" }, + }, + t = { + name = "treesitter", + t = { vim.treesitter.inspect_tree, "show tree" }, + c = { ":=vim.treesitter.get_captures_at_cursor()", "show capture" }, + n = { ":=vim.treesitter.get_node():type()", "show node" }, + }, + }, + s = { + name = "spellcheck", + s = { "Telescope spell_suggest", "spelling" }, + ["/"] = { "setlocal spell!", "spellcheck" }, + n = { "]s", "next" }, + p = { "[s", "previous" }, + g = { "zg", "good" }, + r = { "zg", "rigth" }, + w = { "zw", "wrong" }, + b = { "zw", "bad" }, + ["?"] = { "Telescope spell_suggest", "suggest" }, + }, + g = { + name = "git", + c = { ":GitConflictRefresh", "conflict" }, + g = { ":Neogit", "neogit" }, + s = { ":Gitsigns", "gitsigns" }, + pl = { ":Octo pr list", "gh pr list" }, + pr = { ":Octo review start", "gh pr review" }, + wc = { ":lua require('telescope').extensions.git_worktree.create_git_worktree()", "worktree create" }, + ws = { ":lua require('telescope').extensions.git_worktree.git_worktrees()", "worktree switch" }, + d = { + name = "diff", + o = { ":DiffviewOpen", "open" }, + c = { ":DiffviewClose", "close" }, + }, + b = { + name = "blame", + b = { ":GitBlameToggle", "toggle" }, + o = { ":GitBlameOpenCommitURL", "open" }, + c = { ":GitBlameCopyCommitURL", "copy" }, + }, + }, + w = { + name = "write", + w = { ":w", "write" }, + }, + x = { + name = "execute", + x = { ":w:source %", "file" }, + }, }, { mode = "n", prefix = "" }) local is_code_chunk = function() - local current, range = require("otter.keeper").get_current_language_context() - if current then - return true - else - return false - end + local current, range = require("otter.keeper").get_current_language_context() + if current then + return true + else + return false + end end local insert_code_chunk = function(lang) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", true) - local keys - if is_code_chunk() then - keys = [[o``````{]] .. lang .. [[}o]] - else - keys = [[o```{]] .. lang .. [[}```O]] - end - keys = vim.api.nvim_replace_termcodes(keys, true, false, true) - vim.api.nvim_feedkeys(keys, "n", false) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", true) + local keys + if is_code_chunk() then + keys = [[o``````{]] .. lang .. [[}o]] + else + keys = [[o```{]] .. lang .. [[}```O]] + end + keys = vim.api.nvim_replace_termcodes(keys, true, false, true) + vim.api.nvim_feedkeys(keys, "n", false) end local insert_r_chunk = function() - insert_code_chunk("r") + insert_code_chunk("r") end local insert_py_chunk = function() - insert_code_chunk("python") + insert_code_chunk("python") end -- normal mode wk.register({ - [""] = { "lua vim.lsp.buf.definition()", "go to definition" }, - [""] = { "q", "close buffer" }, - [""] = { "noh", "remove search highlight" }, - ["n"] = { "nzzzv", "center search" }, - ["gN"] = { "Nzzzv", "center search" }, - ["gl"] = { "", "open help link" }, - ["gf"] = { ":e ", "edit file" }, - [""] = { insert_r_chunk, "r code chunk" }, - [""] = { insert_py_chunk, "python code chunk" }, - [""] = { insert_py_chunk, "python code chunk" }, - ["]q"] = { ":silent cnext", "quickfix next" }, - ["[q"] = { ":silent cprev", "quickfix prev" }, + [""] = { "lua vim.lsp.buf.definition()", "go to definition" }, + [""] = { "q", "close buffer" }, + [""] = { "noh", "remove search highlight" }, + ["n"] = { "nzzzv", "center search" }, + ["gN"] = { "Nzzzv", "center search" }, + ["gl"] = { "", "open help link" }, + ["gf"] = { ":e ", "edit file" }, + [""] = { insert_r_chunk, "r code chunk" }, + [""] = { insert_py_chunk, "python code chunk" }, + [""] = { insert_py_chunk, "python code chunk" }, + ["]q"] = { ":silent cnext", "quickfix next" }, + ["[q"] = { ":silent cprev", "quickfix prev" }, }, { mode = "n", silent = true }) -- visual mode wk.register({ - [""] = { "SlimeRegionSend", "run code region" }, - [""] = { ":m'>+`mzgv`yo`z", "move line down" }, - [""] = { ":m'<-2`>my`", "repat last normal mode command" }, - ["q"] = { ":norm @q", "repat q macro" }, + [""] = { "SlimeRegionSend", "run code region" }, + [""] = { ":m'>+`mzgv`yo`z", "move line down" }, + [""] = { ":m'<-2`>my`", "repat last normal mode command" }, + ["q"] = { ":norm @q", "repat q macro" }, }, { mode = "v" }) wk.register({ - [""] = { "SlimeRegionSend", "run code region" }, - ["p"] = { '"_dP', "replace without overwriting reg" }, + [""] = { "SlimeRegionSend", "run code region" }, + ["p"] = { '"_dP', "replace without overwriting reg" }, }, { mode = "v", prefix = "" }) -- insert mode wk.register({ - -- [''] = { ":FeMacoi", "edit code" }, - [""] = { " <- ", "assign" }, - [""] = { " |>", "pipe" }, - [""] = { insert_r_chunk, "r code chunk" }, - [""] = { insert_py_chunk, "python code chunk" }, - [""] = { insert_py_chunk, "python code chunk" }, - [""] = { "", "omnifunc completion" }, + -- [''] = { ":FeMacoi", "edit code" }, + [""] = { " <- ", "assign" }, + [""] = { " |>", "pipe" }, + [""] = { insert_r_chunk, "r code chunk" }, + [""] = { insert_py_chunk, "python code chunk" }, + [""] = { insert_py_chunk, "python code chunk" }, + [""] = { "", "omnifunc completion" }, }, { mode = "i" }) diff --git a/lua/plugins/quarto.lua b/lua/plugins/quarto.lua index 9638301..cf4dab1 100644 --- a/lua/plugins/quarto.lua +++ b/lua/plugins/quarto.lua @@ -694,24 +694,26 @@ return { end, }, - -- paste an image to markdown from the clipboard - -- :PasteImg, + -- paste an image from the clipboard or drag-and-drop { - "dfendr/clipboard-image.nvim", - keys = { - { "ip", ":PasteImg", desc = "image paste" }, - }, - cmd = { - "PasteImg", + "HakonHarnes/img-clip.nvim", + event = "BufEnter", + opts = { + markdown = { + url_encode_path = true, + template = "![$CURSOR]($FILE_PATH)", + drag_and_drop = { + download_images = false, + }, + }, + quarto = { + url_encode_path = true, + template = "![$CURSOR]($FILE_PATH)", + drag_and_drop = { + download_images = false, + }, + }, }, - config = function() - require 'clipboard-image'.setup { - quarto = { - img_dir = "img", - affix = "![](%s)" - } - } - end }, -- preview equations