[mini.jump2d] Remote operations (yy, yiW, yp, y' etc) #2172
Replies: 1 comment 3 replies
-
|
Thanks for sharing! I'll copy some relevant parts from Reddit comments:
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks for sharing! I'll copy some relevant parts from Reddit comments:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Initially posted on reddit, posted here by @echasnovski's suggesion
Related: #1818
Features:
;y, words;w, linesyl, paragraphsyp, contents of parenthesis;(, quotes;';", brackets;{;[, also things like delete a paragraphdp;crlrepeatable = trueEasily extendable for any remote operations, just come up with keymaps that don't conflict with your existing ones
Known issues:
mini-jump2d_remote-operations.mp4
The contents of this gist:
{ -- A sample lazy.nvim import, modify if you use a different plugin manager 'nvim-mini/mini.nvim', -- 'echasnovski/mini.nvim', -- if you haven't migrated to the new path yet config = function() -- Setup and settings which play well with the extended functionality require('mini.jump2d').setup { view = { n_steps_ahead = 3, }, allowed_lines = { blank = false, }, } -- The function itself, copy only the below part if you already have mini.jump2d configured local custom_2d_jump = function(opts) vim.opt.scrolloff = 0 local count = opts.repeatable and vim.v.count1 or 1 if opts.preaction then vim.cmd('normal! ' .. count .. opts.preaction) end if opts.mark then vim.cmd('normal! m' .. opts.mark) end local bufnr = vim.api.nvim_get_current_buf() MiniJump2d.start { labels = opts.homerow and 'asdfghjkl' or 'alksdjfgheivbcmnopqrtuwxyz', spotter = opts.spotter, hooks = { after_jump = function() if opts.end_in_insert then vim.api.nvim_feedkeys(count .. opts.action, 'n', true) else if opts.norepeat_action then vim.cmd('normal! ' .. opts.norepeat_action) end vim.cmd('normal! ' .. count .. opts.action) if opts.action2 then vim.cmd('normal! ' .. count .. opts.action2) end if opts.mark then local cur_bufnr = vim.api.nvim_get_current_buf() if cur_bufnr ~= bufnr then local keys = vim.api.nvim_replace_termcodes('<C-w><C-p>', true, false, true) vim.api.nvim_feedkeys(keys, 'n', true) else vim.cmd('normal! `' .. opts.mark) if opts.afteraction then vim.cmd('normal! ' .. opts.afteraction) end end end end vim.opt.scrolloff = 10 end, }, } end -- Here are various uses that I thought of, ordered by my subjective perception of -- their usefuleness/complexity, modify keybindings as you see fit -- Oh and btw, you can make a function take a count, you'll see how it can be useful -- Those functions are set up with `repeatable = true` -- Copying a Word (yiW) without moving your cursor there -- I use this at least every hour vim.keymap.set('n', ';y', function() custom_2d_jump { mark = 'w', spotter = MiniJump2d.gen_spotter.pattern '[^%s][^%s]+', action = 'yiW', } end) -- Yank an entire line (see how counts may come in handy?) vim.keymap.set('n', 'yl', function() custom_2d_jump { mark = 'l', repeatable = true, homerow = true, spotter = MiniJump2d.builtin_opts.line_start.spotter, action = 'yy', } end) -- Yank a paragraph vim.keymap.set('n', 'yp', function() custom_2d_jump { mark = 'p', repeatable = true, homerow = true, spotter = MiniJump2d.builtin_opts.line_start.spotter, action = 'yip', } end) -- Yank a word (yiw) vim.keymap.set('n', ';w', function() custom_2d_jump { mark = 'w', spotter = MiniJump2d.gen_spotter.pattern '[^%s%p]+', action = 'yiw', } end) -- Below is just a bunch of functions for yanking contents of parenthesis/brackets/quotes vim.keymap.set('n', ";'", function() custom_2d_jump { mark = 'q', spotter = MiniJump2d.gen_spotter.pattern "'.[^']", action = "yi'", } end) vim.keymap.set('n', ';"', function() custom_2d_jump { mark = 'q', spotter = MiniJump2d.gen_spotter.pattern '".[^"]', action = 'yi"', } end) vim.keymap.set('n', ';(', function() custom_2d_jump { mark = 'b', spotter = MiniJump2d.gen_spotter.union(MiniJump2d.gen_spotter.pattern '%(', MiniJump2d.gen_spotter.pattern '%)'), action = 'yi(', } end) vim.keymap.set('n', ';{', function() custom_2d_jump { mark = 'c', spotter = MiniJump2d.gen_spotter.union(MiniJump2d.gen_spotter.pattern '%{', MiniJump2d.gen_spotter.pattern '%}'), action = 'yi{', } end) vim.keymap.set('n', ';[', function() custom_2d_jump { mark = 'b', spotter = MiniJump2d.gen_spotter.union(MiniJump2d.gen_spotter.pattern '%[', MiniJump2d.gen_spotter.pattern '%]'), action = 'yi[', } end) -- Keymaps below are for changing stuff -- Jump and do ciW on a word vim.keymap.set('n', ';c', function() custom_2d_jump { spotter = MiniJump2d.gen_spotter.pattern '[^%s][^%s]+', action = 'ciW', end_in_insert = true, } end) -- Delete a paragraph vim.keymap.set('n', 'dp', function() custom_2d_jump { mark = 'd', repeatable = true, homerow = true, spotter = MiniJump2d.builtin_opts.line_start.spotter, action = 'dip', } end) -- This here is for changing the line you currently hover at, -- with a line that you jump to. And then return to where you were in the first place -- -- Somewhat complicated, I know, but I hope it helps you come up with a -- useful keymap or two that you're tired of typing out manually :) vim.keymap.set('n', 'rl', function() custom_2d_jump { mark = 'l', repeatable = true, homerow = true, spotter = MiniJump2d.builtin_opts.line_start.spotter, preaction = 'dd', norepeat_action = 'P', action = 'j', action2 = 'dd', afteraction = 'P', } end) end, }Beta Was this translation helpful? Give feedback.
All reactions