Skip to content

Conversation

@Kaiser-Yang
Copy link
Contributor

@Kaiser-Yang Kaiser-Yang commented Jun 1, 2025

Related issue

None.

Summary of changes

This option make it possible to bind p to paste after and P to paste before.

For example, I have thoes key mappings:

        map_set({ 'n', 'x' }, '<leader>p', function()
            local plus_reg_content = vim.fn.getreg('+'):gsub('\r', '')
            if not utils.markdown_support_enabled() or #plus_reg_content ~= 0 then
                vim.fn.setreg('+', plus_reg_content, vim.fn.getregtype('+'))
                return '"+p'
            else
                return '<cmd>PasteImage<cr>'
            end
        end, { desc = 'Paste from clipboard or insert image', expr = true })
map_set({ 'n', 'x' }, '<leader>P', function()
    local plus_reg_content = vim.fn.getreg('+'):gsub('\r', '')
    local ok, _ = pcall(require, 'img-clip')
    if not utils.markdown_support_enabled() or #plus_reg_content ~= 0 or not ok then
        vim.fn.setreg('+', plus_reg_content, vim.fn.getregtype('+'))
        utils.feedkeys('"+P', 'n')
    else
        require('img-clip').paste_image({ insert_template_after_cursor = false })
    end
end, { desc = 'Paste from clipboard or insert image' })

Using <leader>p at line 19 (put after line 19, and put cursor at line 20):

image

Using <leader>P at line 19 (put before line 19, and put cursor at line 19; now line 20 is the original line 19):

image

This option make it possible to bind <leader>p to paste after and
<leader>P to paste before.
Copy link
Owner

@hakonharnes hakonharnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. See comments on documentation and tests.

@Kaiser-Yang Kaiser-Yang requested a review from hakonharnes June 8, 2025 12:10
@hakonharnes hakonharnes merged commit e427131 into hakonharnes:main Jun 8, 2025
6 checks passed
@hakonharnes
Copy link
Owner

Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants