Giter Club home page Giter Club logo

clipboard-image.nvim's Introduction

Clipboard Image ๐Ÿ“‹๐Ÿ–ผ๏ธ


License

Installation โ€ข Usage & Demo โ€ข Config


Install

โ— Requirement: xclip (X11), wl-clipboard (Wayland), pngpaste (MacOS)

โ„น๏ธ Run :checkhealth clipboard-image to check a missing dependency

Plugin manager Script
vim-plug Plug 'ekickx/clipboard-image.nvim'
packer.nvim use 'ekickx/clipboard-image.nvim'

Usage

This is the basic usage. If you want to see more you can read API

Command Demo
PasteImg

Config

This plugin is zero config, means you don't need to configure anything to works. But if you want to, you can configure it like this:

Example
require'clipboard-image'.setup {
  -- Default configuration for all filetype
  default = {
    img_dir = "images",
    img_name = function() return os.date('%Y-%m-%d-%H-%M-%S') end, -- Example result: "2021-04-13-10-04-18"
    affix = "<\n  %s\n>" -- Multi lines affix
  },
  -- You can create configuration for ceartain filetype by creating another field (markdown, in this case)
  -- If you're uncertain what to name your field to, you can run `lua print(vim.bo.filetype)`
  -- Missing options from `markdown` field will be replaced by options from `default` field
  markdown = {
    img_dir = {"src", "assets", "img"}, -- Use table for nested dir (New feature form PR #20)
    img_dir_txt = "/assets/img",
    img_handler = function(img) -- New feature from PR #22
      local script = string.format('./image_compressor.sh "%s"', img.path)
      os.execute(script)
    end,
  }
}
Structure

See also API

{
  default = {
    <options>
  },
  <filetype> = {
    <options>
  },
}
Options Default Description
img_dir "img" Directory where the image from clipboard will be copied to
img_dir_txt "img" Directory that will be inserted to buffer.
Example: Your actual dir is src/assets/img but your dir on text or buffer is /assets/img
img_name function() return os.date('%Y-%m-%d-%H-%M-%S') end Image's name
img_handler function(img) end Function that will handle image after pasted.
img is a table that contain pasted image's name and path
affix default: "%s"
markdown: "![](%s)"
asciidoc: "image::%s[]"
String that sandwiched the image's path

Tips

Share your tips here

Questions

You can ask your questions on discussions

Contribute

Read the contribution guide here

Credits

Thanks to:

  • ferrine/md-img-paste.vim, I look some of its code
  • elianiva for giving me feedback on Vim Indonesia (Telegram group)
  • all neovim lua plugin creators and its contributors, I get some inspiration from reading their code

clipboard-image.nvim's People

Contributors

axieax avatar codiy1992 avatar ekickx avatar geier avatar gokulmaxi avatar huynle avatar jakobkhansen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

clipboard-image.nvim's Issues

filetype specific configuration

In case nvim is used to write multiple markup languages (html, md, tex) it would help to configure the plugin like this:

require'clipboard-image'.setup {
  tex = { 
    img_dir = 'img',
    img_dir_txt = 'img',
    img_name = function () return os.date('%Y-%m-%d-%H-%M-%S') end,
    affix = [[\includegraphics{%s}]]
  },
  md = { 
    img_dir = 'img',
    img_dir_txt = 'img',
    img_name = function () return os.date('%Y-%m-%d-%H-%M-%S') end,
    affix = '![](%s)''
  },
...
}

The options can be function or string

I want the option to not only be function, but also string. So the config can be like this:

require'clipboard-image'.setup {
  img_dir = 'src/assets/img',
  img_dir_txt =  '/assets/img',
  img_name = function ()
    local img_dir = require'clipboard-image'.get_config().img_dir()
    local index = 1
    for output in io.popen('ls '..img_dir):lines() do
      if output == 'image'..index..'.png' then
        index = index + 1
      else
        break
      end
    end
    return 'image'..index
  end,
  prefix = '![](',
  suffix = ')'
}

relative path base on file editing?

myconfig "img_dir = {"../assets"}"
this will save image to the assets folder (which is in the parent folder of terminal current path) ,not base on the markdown file nvim is editing.

i hope can config picture folder using relative path base on markdown file.

thank you

Usage on Windows 10

I'm currently running Neovim in Windows 10, I also have a WSL where I can install Linux tools such as the ones needed by this plugin.

How can I set up my Neovim Windows config and eventually WSL to use this plugin under these conditions?

Missing parentheses Error

I installed the plugin and tried to run Run :checkhealth clipboard-image but got the following error.

  health#clipboard-image#check
  ========================================================================
    - ERROR: Failed to run healthcheck for "clipboard-image" plugin. Exception:
       function health#check, line 21
       Vim(call):E107: Missing parentheses '(': health#clipboard-image#check()

My environment is below.

  • NVIM v0.5.1
  • macOS Monterey 12.6

It's in Japanese, but I'll post a picture.
image

Do you have any solutions?
thank you

Way to use hidden directory for img_dir

Greetings.

I was using img_dir = {"%:p:h", ".img"} but it doesn't insert the "." in links like [title](.img/test.png).

Here is my config, need to clean it up still:

require'clipboard-image'.setup {
    -- Default configuration for all filetype
    default = {
        img_dir = {"%:p:h", ".img"},
        img_name = function ()
            vim.fn.inputsave()
            local name = vim.fn.input('Name: ')
            vim.fn.inputrestore()

            if name == nil or name == '' then
                return os.date('%y-%m-%d-%H-%M-%S')
            end
            return name
        end,
        affix = "<\n  %s\n>" -- Multi lines affix
    },
    -- You can create configuration for ceartain filetype by creating another field (markdown, in this case)
    -- If you're uncertain what to name your field to, you can run `lua print(vim.bo.filetype)`
    -- Missing options from `markdown` field will be replaced by options from `default` field
    markdown = {
        img_dir = {"%:p:h", ".img"}, -- Use table for nested dir (New feature form PR #20)
        --img_dir_txt = "/assets/img",
        img_handler = function(img) -- New feature from PR #22
            local script = string.format('./image_compressor.sh "%s"', img.path)
            os.execute(script)
        end,
        affix = "![](%s)", -- Multi lines affix
    }
}

Screenshot

Hi there!

What program are you using in the GIF to take screenshots which is automatically copied to a clipboard?

How to config

Thanks for the amazing plug-in. I just tried it and it works well.
I would like to modify the config so that I can edit filename before it is pasted, and I found the function script is available in the manual.

But I could not find how I can get into the config script. Could you teach me?
Sorry for the stupid question...I know it is too basic to someone who knows lua & neovim well.
I guess it also works if I change config.lua, but it could not be the correct way since
you mentioned require'clipboard-image'.setup { ... and it is not the same as script in config.lua

[FR] Allow `affix` to be multi-lined

Hi,
Thanks for this great plugin.

Currently, it looks that the affix can only be a single-line string.
However, there are some cases that allowing it to be a multi-line string can be useful e.g. latex.
Maybe could this be implemented, please?

`ERROR: platform is not supported` on Linux with xclip installed

Hello there. Hope you're doing well. Thank you for creating this handy plugin; it makes taking notes in nvim much easier!

However, I found a bug. When I first installed it it worked perfectly. Then suddenly I discovered it stopped working.

clipboard-image: require("clipboard-image.health").check()
========================================================================
## Checking dependencies
  - ERROR: platform is not supported

Platform and dependency:

โฏ uname
Linux
โฏ xclip -version
xclip version 0.13
Copyright (C) 2001-2008 Kim Saunders et al.
Distributed under the terms of the GNU GPL

Any input is much appreciated. Thank you:)

Custom pasted text of img_dir

So I imagine a scenario when I want the pasted text's path is different from the real pasted image's path. For example, I want to save the image on assets/img/imgname.png but the pasted text is /img/imgname.png.

module 'health' not found

๎ช‡ Error 19:45:01 msg_show.lua_error E5108: Error executing lua ...lazy/clipboard-image.nvim/lua/clipboard-image/health.lua:3: module 'health' not found:
no field package.preload['health']
cache_loader: module health not found
cache_loader_lib: module health not found
no file './health.lua'
no file '/opt/homebrew/share/luajit-2.1.0-beta3/health.lua'
no file '/usr/local/share/lua/5.1/health.lua'
no file '/usr/local/share/lua/5.1/health/init.lua'
no file '/opt/homebrew/share/lua/5.1/health.lua'
no file '/opt/homebrew/share/lua/5.1/health/init.lua'
no file './health.so'
no file '/usr/local/lib/lua/5.1/health.so'
no file '/opt/homebrew/lib/lua/5.1/health.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
...lazy/clipboard-image.nvim/lua/clipboard-image/health.lua:3: in main chunk
[C]: in function 'require'
.../lazy/clipboard-image.nvim/lua/clipboard-image/paste.lua:4: in main chunk
[C]: in function 'require'
[string ":lua"]:1: in main chunk
,

I was still able to use it for a period of time, but now there is such an error, which cannot be solved by reinstallation.

There is no image data in clipboard

The plugin has recently stopped working for me with the error there is no image data in clipboard. I can tell by pasting in other applications that there is. I am on wayland and checkhealth is succesful.

[Enhancement] Should Allow Use Multiple "%s" and Quotes `"` in Affix

First of all thank you for this awesome plugin! ๐Ÿ˜„

This plugin makes markdown editing with neovim much more convenient, but currently I find it difficult to set strings with multiple "%s" or with quotes as affix, for example, I cannot set

affix = [[<center><img src="%s" alt="%s" style="zoom: 80%" /></center>]]

Clipboard-image will complain:

image

if I set affix as shown.

Create img_dir at the same level as this file

Hi there ,

I often edit a file in other directory , is it possible create img_dir at the same level as the file ?

As the below situation , I wanna $img_dir in the /wiki/work/img/ not in the wiki/img/

Please make this proposal a new feature ๐Ÿ™ ๐Ÿฅฐ

tree .
โ”‚ย ย  โ”œโ”€โ”€ wiki
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ school
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ work
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ personal


cd wiki
vim work/2022-01-01.md

Checkhealth not working

I use lazy.nvim to install the plugin, the setup is

{
    "ekickx/clipboard-image.nvim",
    opts = { -- Default configuration for all filetype
      default = {
        img_dir = { "%:p:h", "img" },
        img_name = function()
          local name = os.date("%y-%m-%d-%H-%M-%S")

          vim.ui.input({ prompt = "Name: ", default = name }, function(input)
            name = input
          end)
          return name
        end,
        affix = "<\n  %s\n>", -- Multi lines affix
      },
      -- You can create configuration for ceartain filetype by creating another field (markdown, in this case)
      -- If you're uncertain what to name your field to, you can run `lua print(vim.bo.filetype)`
      -- Missing options from `markdown` field will be replaced by options from `default` field
      markdown = {
        img_dir = { "src", "assets", "img" }, -- Use table for nested dir (New feature form PR #20)
        img_dir_txt = "/assets/img",
        img_handler = function(img) -- New feature from PR #22
          local script = string.format('./image_compressor.sh "%s"', img.path)
          os.execute(script)
        end,
      },
    },
    ft = { "tex", "markdown" },
    keys = {
      { "<leader>i", "<cmd>PasteImg<cr>", desc = "Paste image" },
    },
  }

which just copy the example settings and add ft and keys for lazy.nvim.
When I run checkhealth cliclipboard-image it output:

==============================================================================
clipboard-image: require("clipboard-image.health").check()

- ERROR Failed to run healthcheck for "clipboard-image" plugin. Exception:
  function health#check, line 25
  Vim(eval):E5108: Error executing lua ...lazy/clipboard-image.nvim/lua/clipboard-image/health.lua:3: module 'health' not found:
  no field package.preload['health']
  cache_loader: module health not found
  cache_loader_lib: module health not found
  no file './health.lua'
  no file '/opt/homebrew/share/luajit-2.1.0-beta3/health.lua'
  no file '/usr/local/share/lua/5.1/health.lua'
  no file '/usr/local/share/lua/5.1/health/init.lua'
  no file '/opt/homebrew/share/lua/5.1/health.lua'
  no file '/opt/homebrew/share/lua/5.1/health/init.lua'
  no file './health.so'
  no file '/usr/local/lib/lua/5.1/health.so'
  no file '/opt/homebrew/lib/lua/5.1/health.so'
  no file '/usr/local/lib/lua/5.1/loadall.so'
  stack traceback:
  [C]: in function 'require'
  ...lazy/clipboard-image.nvim/lua/clipboard-image/health.lua:3: in main chunk
  [C]: in function 'require'
  [string "luaeval()"]:1: in main chunk

Other plugin's checkhealth can run correctly. And also when I run PasteImg it has error

E5108: Error executing lua [string ":lua"]:1: loop or previous error loading module 'clipboard-image.paste'
stack traceback:
	[C]: in function 'require'
	[string ":lua"]:1: in main chunk

Can you help me? Thanks

Not working under WSL2 (tcgetpgrp failed: Not a tty)

Hi, there!
I just found this plugin and installed it via lazy.nvim

When I tried this plugin under the Powershell environment, everything works well, however when I entered the :PasteImage command under the WSL environment, following error occured (I got no idea on why the error output is not selectable so I have to take screenshot. There are also some character displaying issue might due to my system language):

ๅฑๅน•ๆˆชๅ›พ 2023-03-08 161955

I have also checked this issue #34, but it seems like not related.

Thanks for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.