ekickx / clipboard-image.nvim

Neovim Lua plugin to paste image from clipboard.
MIT License
309 stars 51 forks source link

How to config #8

Closed Ka-lip closed 3 years ago

Ka-lip commented 3 years ago

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

ekickx commented 3 years ago

Oh yeah don't worry it's also a note for me to make better documentation. So img_name will use output from the function as image's name. The default config in config.lua means the image's name have Year-Month-Date-Hours-Minute-Second format. While the readme is an example how you can configure the plugin. If you use config in the readme, your image names will be image1, image2, image3, etc.

If you want to manually insert your img_name you can try this

require'clipboard-image'.setup {
  default = {
    img_name = function ()
      vim.fn.inputsave()
      local name = vim.fn.input('Name: ')
      vim.fn.inputrestore()
      return name
    end,
  }
}

Ohh also update the plugin first, I just fixed a bug for inserted text.

ekickx commented 3 years ago

This is the demo clipboard-demo

Ka-lip commented 3 years ago

Thanks for the demo. It looks like the function I want!

The code you showed here is

require'clipboard-image'.setup {
  default = {

But what is in config.lua

M.config = {
  default = {

is it ok to replace the whole default {} block and ignore the difference between M.config and require'clipboard-image'.setup?

I am really sorry that I still asked😣 Thank you again for your patient!

ekickx commented 3 years ago

Oh you don't need to worry about that. config.lua is the default config for this plugin so this plugin can work out of the box without the need for user to manually configure it. If user don't like the default config, they can override it with require'clipboard-image'.setup{}.

Oh and extra note, require'clipboard-image'.setup{} is actually a function, require('clipboard-image').setup{}. It's just lua way to make the syntax simpler. Also that function means, "call setup function from clipboard-image module.

Ka-lip commented 3 years ago

Hi, @ekickx

thanks for the explanation! I just realized that the neovim has some different setting from vim. (I only knew settings in .vimrc before...) That is why I asked you those stupid questions.

What I did is

  1. add a lua file in ~\AppData\Local\nvim\plugin\
  2. paste the code you offered

I hope it is the correct way to implement the custom config. please close the issue if it is the correct way. if it is not correct way, could you teach me then close the issue? thank you very much! 😃

ekickx commented 3 years ago

You can do that or place it in ~\AppData\Local\nvim\lua\. So the difference is:

I personally prefer to place my plugin config in nvim\lua\plugins\plugin_config and load it from ~\AppData\Local\nvim\init.lua like this:

-- this is inside init.lua
require"plugins.plugin_config"

So if I don't need that config I can just comment it like this:

-- this is inside init.lua
-- require"plugins.plugin_config"

But yeah it's up to you. You do you.

Also thank you for opening an issue. I know it takes a lot of courage to open an issue. I experienced it 😅.

Oh yeah you can also check other people's config for reference.