From fff6e6086280bfe672f32bf9e523fdeafa730312 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 10 Feb 2023 11:13:53 +0100 Subject: [PATCH] nvim: Remove cartographer plugin Switch to use the nice new nvim-internal keymapping functions. Cartographer was a really useful plugin when they did not yet exist but now everything I wanted to do can be done without a mapping plugin, so it is time to remove it. --- nvim/.config/nvim/after/plugin/bibcite.vim | 52 ----- nvim/.config/nvim/lazy-lock.json | 1 - nvim/.config/nvim/lua/maps.lua | 243 +++++++++------------ nvim/.config/nvim/lua/plugins.lua | 2 +- 4 files changed, 103 insertions(+), 195 deletions(-) delete mode 100644 nvim/.config/nvim/after/plugin/bibcite.vim diff --git a/nvim/.config/nvim/after/plugin/bibcite.vim b/nvim/.config/nvim/after/plugin/bibcite.vim deleted file mode 100644 index 9b1b248..0000000 --- a/nvim/.config/nvim/after/plugin/bibcite.vim +++ /dev/null @@ -1,52 +0,0 @@ -" set up fzf-bibtex -let g:fzf_bibtex_cache = '~/.cache/' -let g:fzf_bibtex_sources = g:pandoc#biblio#bibs - -" prepare bibtex_ls function to look for bib files in cwd/parent/subdirs, -" attach the standard bibtex source file -" return the command with standard cache directory filled -function! s:bibtex_ls(...) - let bibfiles = ( - \ globpath('.', '*.bib', v:true, v:true) + - \ globpath('..', '*.bib', v:true, v:true) + - \ globpath('*/', '*.bib', v:true, v:true) - \ ) - let bibfiles = join(bibfiles, ' ') - let source_cmd = 'bibtex-ls -cache ' . g:fzf_bibtex_cache . ' ' .bibfiles . ' ' . join(g:fzf_bibtex_sources) - return source_cmd -endfunction - -" NORMAL MODE CITATION -" insert citation from normal mode at cursor (with brackets) -function! s:bibtex_cite_sink(lines) - let r=system("bibtex-cite ", a:lines) - execute ':normal! i[' . r . ']' -endfunction -command! -bang -nargs=* CiteRef call fzf#run(fzf#wrap({ - \ 'source': bibtex_ls(), - \ 'sink*': function('bibtex_cite_sink'), - \ 'up': '25%', - \ 'options': '--ansi --multi --prompt "Cite> "' - \ })) - -" INSERT MODE CITATION -" insert citation from insert mode at cursor (no brackets inserted) -function! s:bibtex_cite_sink_insert(lines) - let r=system("bibtex-cite ", a:lines) - execute ':normal! i' . r - call feedkeys('a', 'n') -endfunction - -" MARKDOWN CITATION -" insert markdown formatted reference -function! s:bibtex_markdown_sink(lines) - let r=system("bibtex-markdown -cache " . g:fzf_bibtex_cache . ' ' . join(g:fzf_bibtex_sources), a:lines) - echo join(a:lines, '; ') - execute ':normal! a' . r -endfunction -command! -bang -nargs=* CiteMarkdown call fzf#run(fzf#wrap({ - \ 'source': bibtex_ls(), - \ 'sink*': function('bibtex_markdown_sink'), - \ 'up': '25%', - \ 'options': '--ansi --multi --prompt "Markdown> "' - \ })) diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 1cfd68a..7d87556 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -33,7 +33,6 @@ "notational-fzf-vim": { "branch": "master", "commit": "75c2c31e7cd77397018c5777804666d648557537" }, "nui.nvim": { "branch": "main", "commit": "d147222a1300901656f3ebd5b95f91732785a329" }, "nvim-base16.lua": { "branch": "master", "commit": "b336f40462b3ca1ad16a17c195b83731a2942d9a" }, - "nvim-cartographer": { "branch": "master", "commit": "fbe977c9529019376db9426cccf04bfdadeafc69" }, "nvim-cmp": { "branch": "main", "commit": "cfafe0a1ca8933f7b7968a287d39904156f2c57d" }, "nvim-colorizer.lua": { "branch": "master", "commit": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6" }, "nvim-lspconfig": { "branch": "master", "commit": "aeb76066212b09c7c01a3abb42fe82f0130ef402" }, diff --git a/nvim/.config/nvim/lua/maps.lua b/nvim/.config/nvim/lua/maps.lua index 44a9365..f9c8fe5 100644 --- a/nvim/.config/nvim/lua/maps.lua +++ b/nvim/.config/nvim/lua/maps.lua @@ -1,34 +1,30 @@ -local map = require 'cartographer' +local map = vim.keymap.set -- The general ideas behind these mappings: -- -- * Leader prefix is the generally preferred way to map new things, however --- only for those that affect all of vim +-- only for those that affect all of vim of work in a supra-buffer way. -- --- * Localleader prefix is used for mappings which only affect single buffers, --- in other words mostly filetype specific mappings --- --- many of these mapping ideas come from Tom Ryder who has them nicely --- documented +-- * Localleader prefix is used for mappings which only affect single buffers. +-- In other words mostly filetype specific mappings -- backspace to switch to alternate (last) buffer -map.n.nore[''] = '' +map('n', '', '') -- since u undoes, would it not make sense that U redoes? -map.n.nore['U'] = '' +map('n', 'U', '') -- d-motion puts the last 'deleted' thing into the default register to paste; -- use D-motion to truly delete something into nothingness and keep whatever -- you want in your register, ready to paste -map.n.nore['D'] = '"_d' +map('n', 'D', '"_d') --- I don't particularly need ex mode (at least, yet) but faster macro access --- is nice -map.n.nore['Q'] = '@' +-- I don't particularly need ex mode (at least, yet) but faster macro access is nice +map('n', 'Q', '@') -- stronger versions of left,right - move all the way to beginning/end of line -map.n.nore['H'] = '^' -map.n.nore['L'] = '$' +map('n', 'H', '^') +map('n', 'L', '$') -- when in softwrapped files, allow moving through the visible lines with j/k -- but when prepending a number jump *exactly* as many lines, wrapped or not @@ -44,41 +40,37 @@ local function wrap_down() return 'j' end -map.n.nore.expr['k'] = wrap_up -map.n.nore.expr['j'] = wrap_down +map('n', 'k', wrap_up, {expr = true}) +map('n', 'j', wrap_down, {expr = true}) -- move around between matching brackets with tab -map.n.nore[''] = '%' +map('n', '', '%') -- when in insertion mode, C-u uppercases the current word, C-l lowercases it, -map.i.nore[''] = 'gUiw`]a' -map.i.nore[''] = 'guiw`]a' - --- let me save stuff as sudo when I forget to call vim with it -map.c.nore['w!!'] = -[[execute 'silent! write !sudo tee % >/dev/null' edit!]] +map('i', '', 'gUiw`]a') +map('i', '', 'guiw`]a') -- yank current filename/filepath to f buffer -map.n.nore['yp'] = ':let @p = expand("%")' -map.n.nore['yP'] = ':let @p = expand("%:p")' +map('n', 'yp', ':let @p = expand("%")') +map('n', 'yP', ':let @p = expand("%:p")') -- repeat the last substitute command with all its flags preserved -map.n.nore['&'] = ':&&' +map('n', '&', ':&&') -- bracket pairings to go to the next/previous of: -- (works with count prefixes) -- Argument list -map.n.nore['[a'] = ':previous' -map.n.nore[']a'] = ':next' +map('n', '[a', ':previous') +map('n', ']a', ':next') -- Buffers -map.n.nore['[b'] = ':bprevious' -map.n.nore[']b'] = ':bnext' +map('n', '[b', ':bprevious') +map('n', ']b', ':bnext') -- Quickfix list -map.n.nore['[q'] = ':cprevious' -map.n.nore[']q'] = ':cnext' +map('n', '[q', ':cprevious') +map('n', ']q', ':cnext') -- Location list -map.n.nore['[l'] = ':lprevious' -map.n.nore[']l'] = ':lnext' +map('n', '[l', ':lprevious') +map('n', ']l', ':lnext') -- maps the leader for buffer local mappings -- since we are (atm) using sneak to go fwd/bwd in fFtT searches, comma does @@ -87,180 +79,149 @@ vim.g.maplocalleader = "," -- If we mapped localleader to comma, we can still get to its original function -- by douple-tapping it. +-- FIXME does this work still (and is it necessary)? if vim.g.maplocalleader == ',' then - map.nore[',,'] = ',' - map.s[',,'] = nil + map('', ',,', ',') + vim.keymap.del('', ',,', {silent=true}) end -- remove search highlights by pressing space+/ -map.n.nore['/'] = ':noh' +map('n', '/', ':noh') -- split buffers vertically/horizontally with the leader \ or - (mirrors my -- tmux setup) -map.n.nore['-'] = ':sp' -map.n.nore['\\'] = ':vsp' +map('n', '-', ':sp') +map('n', '\\', ':vsp') -- 'open new buffer' with leader-t (opens new buffer containing current dir and switches to it) -map.n.nore['t'] = ':vsp .' +map('n', 't', ':vsp .') -- open actual new tab with leader-T -map.n.nore['T'] = ':tabedit .' +map('n', 'T', ':tabedit .') -- select the whole buffer with -a -map.n.nore['a'] = 'ggVG' +map('n', 'a', 'ggVG') --- CONFIG EDITING --- quickly edit vimrc with leader+V -map.n.nore['V'] = ':vsp $MYVIMRC' --- source vimrc with keystroke combination -map.n.nore['VV'] = ':source $MYVIMRC' +-- PLUGIN: Navigator.nvim +map('n', 'h', 'lua require("Navigator").left()', {silent = true}) +map('n', 'k', 'lua require("Navigator").up()', {silent = true}) +map('n', 'l', 'lua require("Navigator").right()', {silent = true}) +map('n', 'j', 'lua require("Navigator").down()', {silent = true}) +map('n', 'p', 'lua require("Navigator").previous()', {silent = true}) -- PLUGIN: Vifm.vim -- open/close file tree with leader-e -map.n.nore['e'] = ':Vifm' +map('n', 'e', ':Vifm') -- open current file tree with current file directory -map.n.nore['E'] = ':Vifm getcwd()' +map('n', 'E', ':Vifm getcwd()') -- PLUGIN: Telescope GLOBAL FUZZY FINDING -- buffers and files in current workdir -map.n.nore['s'] = -[[:lua require 'telescope.builtin'.buffers(require 'telescope.themes'.get_ivy())]] +map('n', 's',":lua require 'telescope.builtin'.buffers(require 'telescope.themes'.get_ivy())") -- most recently used / MRU, bound to S since it is essentially a larger -- go-back intention than just buffers -map.n.nore['S'] = -[[:lua require 'telescope.builtin'.oldfiles(require 'telescope.themes'.get_ivy())]] +map('n', 'S',":lua require 'telescope.builtin'.oldfiles(require 'telescope.themes'.get_ivy())") -- fuzzy find files in cwd -map.n.nore['f'] = [[:lua require 'telescope.builtin'.find_files()]] +map('n', 'f',":lua require 'telescope.builtin'.find_files()") -- fuzzy find hidden files in cwd -map.n.nore[''] = -[[:lua require 'telescope.builtin'.find_files({hidden=true})]] +map('n', '',":lua require 'telescope.builtin'.find_files({hidden=true})") -- general full-text search in cwd with rg -map.n.nore['F'] = [[:lua require 'telescope.builtin'.live_grep()]] +map('n', 'F',":lua require 'telescope.builtin'.live_grep()") -- git status -map.n.nore['gs'] = [[:lua require 'telescope.builtin'.git_status()]] +map('n', 'gs',":lua require 'telescope.builtin'.git_status()") -- git buffercommits -map.n.nore['gb'] = -[[:lua require 'telescope.builtin'.git_bcommits()]] +map('n', 'gb',":lua require 'telescope.builtin'.git_bcommits()") -- git commitlog -map.n.nore['gl'] = -[[:lua require 'telescope.builtin'.git_commits()]] +map('n', 'gl',":lua require 'telescope.builtin'.git_commits()") -- helptags -map.n.nore[''] = -[[:lua require 'telescope.builtin'.help_tags()]] +map('n', '',":lua require 'telescope.builtin'.help_tags()") -- manpages -map.n.nore[''] = -[[:lua require 'telescope.builtin'.man_pages()]] +map('n', '',":lua require 'telescope.builtin'.man_pages()") -- colorschemes -map.n.nore[''] = -[[:lua require 'telescope.builtin'.colorscheme(require 'telescope.themes'.get_ivy())]] +map('n', '',":lua require 'telescope.builtin'.colorscheme(require 'telescope.themes'.get_ivy())") -- spell suggestions -map.n.nore['z='] = -[[:lua require 'telescope.builtin'.spell_suggest(require 'telescope.themes'.get_ivy())]] +map('n', 'z=',":lua require 'telescope.builtin'.spell_suggest(require 'telescope.themes'.get_ivy())") --- Note Searching --- PLUGIN: Notational-FZF --- set notational-fzf-vim keys for the NV window itself -vim.g.nv_fzf_binds = { - 'alt-a:select-all', 'alt-q:deselect-all', 'alt-p:toggle-preview', - 'alt-u:page-up', 'alt-d:page-down', 'ctrl-w:backward-kill-word' -} --- FZF note full-text search with notational-velocity like functions (in wiki --- directory) -map.n.nore['n'] = ':NV' -map.n.nore['N'] = ':NV!' -- Format current Paragraph (esp useful in prose writing) -map.n.nore.silent['q'] = 'gqap' -map.x.nore.silent['q'] = 'gq' -map.n.nore.silent['Q'] = 'vapJgqap' +map('n', 'q', 'gqap', {silent=true}) +map('x', 'q', 'gq', {silent=true}) +map('n', 'Q', 'vapJgqap', {silent=true}) -map.n.silent['mp'] = 'MarkdownPreviewToggle' +map('n', 'mp', 'MarkdownPreviewToggle') -- FORMAT code with -- PLUGIN: formatter.nvim -map.n.nore.silent['f'] = ':FormatLock' -map.n.nore.silent['F'] = ':FormatWriteLock' +map('n', 'f', ':FormatLock') +map('n', 'F', ':FormatWriteLock') -- Enter distraction free prose mode with F11 -map.n.nore.silent[''] = ':ZenMode' - --- PLUGIN: fzf-bibtex --- map @@ to automatically insert citation reference at cursor -map.i.nore.silent['@@'] = 'u:CiteRef' --- map cc to insert a complete citation at cursor +map('n', '', ':ZenMode', {silent=true}) -- SPELL CHECKING -- Move to the prev/next spelling error with [S ]S -- Move to the prev/next spelling error or suggestion with [s ]s -map.n.nore['ZZ'] = ':setlocal spell! spelllang=en_us,de_de' -map.n.nore['ZE'] = ':setlocal spell! spelllang=en_us' -map.n.nore['ZG'] = ':setlocal spell! spelllang=de_de' +map('n', 'ZZ', ':setlocal spell! spelllang=en_us,de_de') +map('n', 'ZE', ':setlocal spell! spelllang=en_us') +map('n', 'ZG', ':setlocal spell! spelllang=de_de') -- undo last spelling mistake from insert and normal mode -map.i.nore[''] = 'u[s1z=`]au' -map.n.nore['s'] = 'ms[s1z=`s' +map('i', '', 'u[s1z=`]au') +map('n', 's', 'ms[s1z=`s') -- PLUGIN: easy-align -- Start interactive EasyAlign in visual mode (e.g. vipga) -map.x['ga'] = '(EasyAlign)' +map('x', 'ga', '(EasyAlign)') -- Start interactive EasyAlign for a motion/text object (e.g. gaip) -map.n['ga'] = '(EasyAlign)' +map('n', 'ga', '(EasyAlign)') --- PLUGIN: Navigator.nvim -map.n.nore.silent['h'] = "lua require('Navigator').left()" -map.n.nore.silent['k'] = "lua require('Navigator').up()" -map.n.nore.silent['l'] = "lua require('Navigator').right()" -map.n.nore.silent['j'] = "lua require('Navigator').down()" -map.n.nore.silent['p'] = "lua require('Navigator').previous()" - --- PLUGIN: compe.nvim --- lsp keymaps are set in lsp settings, only for lsp buffers -map.i.nore.expr.silent[''] = 'compe#complete()' -map.i.expr[''] = -[[vsnip#jumpable(1) ? '(vsnip-jump-next)' : '']] -map.i.expr[''] = -[[vsnip#jumpable(-1) ? '(vsnip-jump-next)' : '']] +-- PLUGIN: vnsip +-- jump around in snippets +map('i', '', [[vsnip#jumpable(1) ? '(vsnip-jump-next)' : '']], {expr=true}) +map('i', '', [[vsnip#jumpable(-1) ? '(vsnip-jump-next)' : '']], {expr=true}) -- PLUGIN: symbols-outline.nvim -map.n.nore.silent['o'] = "SymbolsOutline" +map('n', 'o', 'SymbolsOutline', {silent=true}) -- trim trailing whitespaces with mini.nvim trailspace -vim.keymap.set("n", "w", function() require("mini.trailspace").trim() end, {noremap = true}) +map("n", "w", function() require("mini.trailspace").trim() end, {noremap = true}) -- PLUGIN: dial-increment -vim.keymap.set("n", "", require("dial.map").inc_normal(), {noremap = true}) -vim.keymap.set("n", "", require("dial.map").dec_normal(), {noremap = true}) -vim.keymap.set("v", "", require("dial.map").inc_visual(), {noremap = true}) -vim.keymap.set("v", "", require("dial.map").dec_visual(), {noremap = true}) -vim.keymap.set("v", "g",require("dial.map").inc_gvisual(), {noremap = true}) -vim.keymap.set("v", "g",require("dial.map").dec_gvisual(), {noremap = true}) +map("n", "", require("dial.map").inc_normal(), {noremap = true}) +map("n", "", require("dial.map").dec_normal(), {noremap = true}) +map("v", "", require("dial.map").inc_visual(), {noremap = true}) +map("v", "", require("dial.map").dec_visual(), {noremap = true}) +map("v", "g",require("dial.map").inc_gvisual(), {noremap = true}) +map("v", "g",require("dial.map").dec_gvisual(), {noremap = true}) -- PLUGIN: zettelkasten.nvim -map.n.nore[''] = [[:silent lua require 'zettelkasten'.link_follow()]] -map.v.nore[''] = [[:lua require 'zettelkasten'.link_follow(true)]] -map.n.nore['ww'] = [[:lua require 'zettelkasten'.index_open() ]] +map('n', '', [[:silent lua require 'zettelkasten'.link_follow()]]) +map('v', '', [[:lua require 'zettelkasten'.link_follow(true)]]) +map('n', 'ww', [[:lua require 'zettelkasten'.index_open() ]]) -- PLUGIN: toggleterm.nvim -- create a lazygit window, set up in toggleterm settings -map.n.nore['G'] = ':Lazygit' +map('n', 'G', ':Lazygit') -- PLUGIN: magma-nvim -- Operate jupyter notebooks from within vim -map.n.nore.silent['rr'] = ':MagmaEvaluateLine' -map.n.nore.silent['R'] = '?^```{jV/```k:MagmaEvaluateVisual' -map.x.nore.silent['r'] = ':MagmaEvaluateVisual' -map.n.nore.expr.silent['r'] = "nvim_exec('MagmaEvaluateOperator', v:true)" -map.n.nore.silent['re'] = ':MagmaReevaluateCell' -map.n.nore.silent['ro'] = ':MagmaShowOutput' -map.n.nore.silent['rq'] = ':noautocmd :MagmaEnterOutput' -map.n.nore.silent['rc'] = ':MagmaDelete' -map.n.nore.silent['rd'] = ':MagmaInterrupt' +map('n', 'mm', ':MagmaEvaluateLine', {silent=true}) +map('n', 'M', '?^```{jV/```k:MagmaEvaluateVisual', {silent=true}) +map('x', 'm', ':MagmaEvaluateVisual', {silent=true}) +map('n', 'm', "nvim_exec('MagmaEvaluateOperator', v:true)", {expr=true, silent=true}) +map('n', 'mr', ':MagmaReevaluateCell', {silent=true}) +map('n', 'ma', ':MagmaShowOutput', {silent=true}) +map('n', 'mq', ':noautocmd :MagmaEnterOutput', {silent=true}) +map('n', 'md', ':MagmaDelete', {silent=true}) +map('n', 'ms', ':MagmaInterrupt') +map('n', 'mI', ':MagmaInit ') +map('n', 'mD', ':MagmaDeinit') +map('n', 'mR', ':MagmaRestart') -map.n.nore.silent['rO'] = ':lua vim.g.magma_automatically_open_output = not(vim.g.magma_automatically_open_output)' -- jump to beginning of previous/ next cell code -map.n.nore[']r'] = '/^```{}:nohl' -map.n.nore['[r'] = '?^```n}:nohl' +map('n', ']c', '/^```{}:nohl') +map('n', '[c', '?^```n}:nohl') -- insert cell header above/below -map.n.nore['cO'] = ':IPythonCellInsertAbovea' -map.n.nore['co'] = ':IPythonCellInsertBelowa' +map('n', 'mo', 'o```{python}```k') +map('n', 'mO', 'O```{python}```k') diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 78b1647..2653f71 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -82,7 +82,7 @@ return { 'echasnovski/mini.nvim', version = '*', config = function() require('plug._mini') end - }, {'Iron-E/nvim-cartographer'}, -- makes it easier to set mappings through lua + }, { "akinsho/nvim-toggleterm.lua", -- simpler, programmable and multiple terminal toggling for nvim config = function() require('plug._toggleterm') end,