Paste images into nvim

When taking notes, writing documentation or a blog post, I often want to include images, screenshots and such. The process of creating or downloading them, putting them into the correct folder and then fetching the correct path to put into your editor is tedious.

A quick online search later, I found a reddit post leading to a great neovim plugin called img-clip.nvim . This allows me to drag and drop images into my editor. It will autodetect the language I’m using (Markdown, HTML, etc) and create an appropiate image tag, and also copy that image into my project. This also works with images inside the clipboard.

With being new to neovim, I ran into some issues configuring this plugin. It would not behave as I expected it to behave with the default configuration, so I had to find out how to use it. As always, there are plenty of ways on how to achieve this and the internet is full of different approaches that won’t work right out of the box. But if it was easy, everyone could do it - right?

Now my configuration looks like this:

# plugins/img-clip.lua
return {
  {
    "HakonHarnes/img-clip.nvim",
    event = { "BufEnter", "BufNewFile" },
    opts = {
      default = {
        dir_path = "images",
        relative_to_current_file = true,
      },
    },
    keys = {
      { "<leader>pi", "<cmd>PasteImage<cr>", desc = "Paste clipboard image" },
    },
  },
}

Tip

It also seems that config changes are not fully loaded automatically into nvim, but you actually have to restart the whole editor, which seems counterintuitive since you’re getting a notice that the config has been reloaded.

This config will insert a pasted image right into the folder ‘images’ right where I edit my article and create a markdown image tag, just as I want it to be.

Right now the plugin is a little unflexible, as it does not support per project configuration, but there is a merge request that will solve this issue.

comments powered by Disqus

Related Posts

An introduction into amateur radio and why YOU should pick it up as well ...

An introduction into amateur radio and why YOU should pick it up as well ...

You might have heard about a technology called radio. In fact youre using it on a daily base, it’s omnipresent in our modern world.

Read More

LazyVim? Good or bad idea?

I recently started to use vim and fiddled around with creating my own configs and others.

Read More
An introduction into amateur radio and why YOU should pick it up as well ... outdoor edition

An introduction into amateur radio and why YOU should pick it up as well ... outdoor edition

Outdoors you will encounter areas without any cellpone service. Places you may actively look for in order to get away from the stress of your daily grind.

Read More