Giter Club home page Giter Club logo

codesnap.nvim's Introduction

image

Neovim release action status release action status Issues License stars made with lua written in rust

CodeSnap.nvim

📸 Snapshot plugin with rich features that can make pretty code snapshots for Neovim

🚣Migration

If you have installed v0.x before, this chapter will show you what break changes version v1.x introduced.

  • The CodeSnapPreviewOn command is not supported, if you prefer live-preview, you can pin CodeSnap.nvim version to v0.0.11 to continue using this command.
  • The opacity and preview_title config has been removed from v1.0.0
  • The editor_font_family was renamed to code_font_family

v1.x has a different architecture and better performance than v0.x, and v1.x can generate screenshots directly without an open browser. We recommend you upgrade to v1.x for a better experience.

✨Features

  • 🤩 Beautiful code snap template
  • 😎 Custom watermark and window style
  • 💻 Beautiful Mac-style title bar
  • 🤖 Generate snapshots using only a single command
  • 🍞 Breadcrumbs for display file path
  • 🌊 More beautiful background theme
  • 🔢 Support for display line number make sharing code snapshot easier

Prerequirements

  • Neovim 0.9.0+

Install

We recommend using Lazy.nvim to install CodeSnap.nvim, but you can still use another plugin manager you prefer.

Lazy.nvim

{ "mistricky/codesnap.nvim", build = "make" },

Packer

use {'mistricky/codesnap.nvim', run = 'make'}

Vim-Plug

Plug 'mistricky/codesnap.nvim', { 'do': 'make' }

It's worth mentioning that the screenshot feature is implemented by a module called generator written in Rust, when make the project, the CodeSnap.nvim will mount a precompiled cross-compile generator shared file into the plugin that depends on what OS you are using.

We precompiled the following targets:

  • x86_64-unknown-linux-gnu
  • x86_64-apple-darwin
  • aarch64-apple-darwin

If your platform is in the above list, you can just run make after the plugin is installed like the above examples do, CodeSnap.nvim will automatically mount the shared file into the plugin. This means you don't need any Rust utils to compile manually from source.

Compile from source

You need to install Rust development environment before compiling from source, you can refer Install Rust for more detail.

Please keep in mind, cross-compile to these platforms only helps a portion of users to have out-of-box experience, if your platform is not in the above targets list, you still need to compile from source using make build_generator, for instance using Lazy:

{ "mistricky/codesnap.nvim", build = "make build_generator" },

We always recommend you to compile CodeSnap.nvim from source instead of using the precompiled shared file, because the correctness and consistency of compiling from source are always higher than cross-compiling.

Compile on ARM

If you try to compile CodeSnap.nvim on ARM architecture, you may need to install additional dependencies to compile it, thanks @matteocavestri mentioned in #53 (comment)

export CC=gcc
sudo dnf install libuv libuv-devel # On RHEL based systems
sudo apt-get install libtool libuv1-dev # On Debian based systems

Keymappings

If you use Lazy.nvim as your package manager, here are some examples show you how to configure keymappings for CodeSnap:

{
  "mistricky/codesnap.nvim",
  build = "make build_generator",
  keys = {
    { "<leader>cc", "<cmd>CodeSnap<cr>", mode = "x", desc = "Save selected code snapshot into clipboard" },
    { "<leader>cs", "<cmd>CodeSnapSave<cr>", mode = "x", desc = "Save selected code snapshot in ~/Pictures" },
  },
  opts = {
    save_path = "~/Pictures",
    has_breadcrumbs = true,
    bg_theme = "bamboo",
  },
}

Usage

CodeSnap.nvim provides the following two ways to take snapshots of currently selected code

Copy into the clipboard

To take a beautiful snapshot use CodeSnap.nvim, you can just use CodeSnap command to generate a snapshot of the current selected code, then the CodeSnap.nvim will write the snapshot into the clipboard, and you can paste it anywhere you want.

Clipboard.mov

Copy into clipboard on Linux Wayland

Copy screenshots directly into the clipboard is cool, however, it doesn't work well on wl-clipboard, because the wl-clipboard can't paste the content which come from exited processes. As Hyprland document say:

When we copy something on Wayland (using wl-clipboard) and close the application we copied from, the copied data disappears from the clipboard and we cannot paste it anymore. So to fix this problem we can use a program called as wl-clip-persist which will preserve the data in the clipboard after the application is closed.

If you using CodeSnap.nvim on wl-clipboard, you can refer wl-clip-persist, it reads all the clipboard data into memory and then overwrites the clipboard with the data from our memory to persist copied data.

Save the snapshot

Of course, you can use CodeSnapSave command to save the snapshot to path where you defined it in config.save_path

require("codesnap").setup({
  -- The save_path must be ends with .png, unless when you specified a directory path,
  -- CodeSnap will append an auto-generated filename to the specified directory path
  -- For example:
  -- save_path = "~/Pictures"
  -- parsed: "~/Pictures/CodeSnap_y-m-d_at_h:m:s.png"
  -- save_path = "~/Pictures/foo.png"
  -- parsed: "~/Pictures/foo.png"
  save_path = ...
})
Save.mov

Specify language extension

In some scenarios, CodeSnap.nvim cannot auto-detect what language syntax should used to highlight code, for example, shell script can have no extension, they specify interpreters using shebang.

CodeSnap.nvim won't read the whole content of the file, thus cannot detect what language syntax is this, in this case, you can specify extension explicitly, for instance:

CodeSnapSave sh
CodeSnap sh

Breadcrumbs

Breadcrumbs are something to display the current snapshot file path, you can open it through config has_breadcrumbs:

require("codesnap").setup({
  -- ...
  has_breadcrumbs = true
})

The breadcrumbs look like: image

Custom path separator

The CodeSnap.nvim uses / as the separator of the file path by default, of course, you can specify any symbol you prefer as the custom separator:

require("codesnap").setup({
  -- ...
  has_breadcrumbs = true
  breadcrumbs_separator = "👉"
})

image

Line number

We also support displaying line number, you can set has_line_number to true to display line number.

require("codesnap").setup({
  // ...
	has_line_number = true,
})

image

Custom background

The CodeSnap.nvim comes with many beautiful backgrounds preset, you can set any background you like by setting bg_theme to its name, just like:

require("codesnap").setup({
  -- The "default" background is one you see at the beginning of the README
  bg_theme = "default"
})
bamboo sea
peach grape
dusk summer

Solid color background

If you prefer solid color background, you can set bg_color to your preferred color. For example:

require("codesnap").setup({
  -- ...
  bg_color = "#535c68"
})

CodeSnap

Watermark

Watermark is something that makes screenshots more personalized, but if you don't like watermark just set it as an empty string to hide it.

require("codesnap").setup({
  -- ...
  watermark = ""
})

Commands

CodeSnap # Take a snapshot of the currently selected code and copy the snapshot into the clipboard

CodeSnapSave # Save the snapshot of the currently selected code and save it on the disk

Lua

local codesnap <const> = require("codesnap")

-- Take a snapshot of the currently selected code and copy the snapshot into the clipboard
codesnap.copy_into_clipboard()

-- Save the snapshot of the currently selected code and save it on the disk
codesnap.save_snapshot()

Configuration

Define your custom config using setup function

require("codesnap").setup({...})

There is a default config:

{
    mac_window_bar = true,
    title = "CodeSnap.nvim",
    code_font_family = "CaskaydiaCove Nerd Font",
    watermark_font_family = "Pacifico",
    watermark = "CodeSnap.nvim",
    bg_theme = "default",
    breadcrumbs_separator = "/",
    has_breadcrumbs = false,
    has_line_number = false
}

Contribution

CodeSnap.nvim is a project that will be maintained for the long term, and we always accepts new contributors, please feel free to submit PR & issues.

The commit message convention of this project is following commitlint-wizardoc.

License

MIT.

codesnap.nvim's People

Contributors

a-h4nu avatar elliottminns avatar marqmitk avatar mistricky avatar mrwinston avatar nadir-ishiguro avatar nexxai avatar ocya1011 avatar okuramasafumi avatar uzaaft 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  avatar

codesnap.nvim's Issues

More info on install

Maybe I'm stupid, but while trying to install, I just added specified line to packer plugin list, and I get this error on init:


Error detected while processing /home/pickle/.config/nvim/init.lua:
E5113: Error while calling lua chunk: Vim:E475: Invalid value for argument cmd: '/home/pickle/.config/nvim/site/pack/packer/start/codesna
p.nvim/snap-server/target/release/snap-server' is not executable
stack traceback:
        [C]: in function 'connect'
        .../pack/packer/start/codesnap.nvim/lua/codesnap/client.lua:29: in function 'init'
        .../pack/packer/start/codesnap.nvim/lua/codesnap/client.lua:33: in function 'start'
        ...te/pack/packer/start/codesnap.nvim/lua/codesnap/init.lua:15: in function 'setup'
        /home/pickle/.config/nvim/init.lua:39: in main chunk

I mean I get that server-snap is not installed, but at which point should it? and is there some command that copies rust binary to path or something? kinda confused it has not happened yet

Breadcrumbs support

Need a breadcrumbs component to display $pwd which come from Neovim instance

Question about configuring padding for code screenshots

I am using a code screenshot plugin in nvim and I’m not sure how to configure the padding for the code screenshot content. Sometimes I want to set the padding to be smaller, or even completely remove it. Is there a way to achieve this configuration? Thank you for your help!

Not working with a Windows Subsystem for Linux

I am using a WSL with Ubuntu, I followed all the installation steps correctly, but when I run the CodeSnapPreviewOn command, I get the message of the image, I am not an expert in these matters :(

image

Code highlighting in PHP is... weird?

I apologize for the less than descriptive title, but let me explain with screenshots.

Let's say I have this PHP class:
Screenshot 2024-04-08 at 10 04 55 PM

If I select this text:
Screenshot 2024-04-08 at 10 05 31 PM

the highlighting works perfectly:
faaa5d4c-b43f-4522-a984-0ed4652d1bcb

But if I simply miss including the <?php tag at the top of every PHP file in the selection:
Screenshot 2024-04-08 at 10 06 38 PM

Everything stays dark:
71b59030-99bf-471a-bbab-91d0e5422e08

Now, OK, at first glance it seems like it's using the opening tag to figure out the language, and since it isn't sure, it doesn't do anything, but it does highlight very common coding words but only ever in PHP DocBlock comments:
82062d6c-7ba9-492e-938e-570373f2f081

Is there anything I can do about this, or am I just kind of stuck?

Windows guidance

Hi,

Would be good with some guidance of how to do this in a Windows 10 environment.
I tried to compile with both make and cargo / rust from cygwin.

make issue

Unknown platform
cp: cannot stat 'lua/Unknowngenerator.so': No such file or directory
make: *** [makefile:2: build] Error 1

cargo failed in a later state with unresolved symbols refs.

error LNK2019: unresolved external symbol

No theme option

I didn't like the backgrounds. I just wanted a solid codesnippet, without backgrounds.
I just added this to the theme:

"none" => vec![
                GradientStop::new(0., Color::from_rgba8(0, 0, 0, 0))
            ],

Example:
with_background
no_background

Try to drag the image and you will see the difference.

Hi, I am getting: Command `CodeSnap` not found after loading `codesnap.nvim`

  1. It takes too much time to compile, not the reason of coming here...
  2. I have to select the next line for preview, see video
2024-02-23_23-54-04.mp4
  1. I want the watermark to be the $(PWD) any way to do so? Like:
echo $PWD
> /home/daUnknownCoder/.config/NeutronVim

image

  1. I would also like to change the title of the window from React App to <My Custom Title> is that possible?
  2. Custom Installable font instead of most probably Pacifico in watermark?

See i really like the project but if these can be resolved then this project will be a gr8 success

save_path is not a path but a specific filename

I was expecting save_path to take a directory as parameter, not a specific filename.

e.g. save_path = /home/me/snapshots/"

and for it to auto-generate filenames for that directory.

Instead it seems to take a specific named file only:

require("codesnap").setup({
	save_path = "/tmp/snap.png"
})

Which seems a lot less useful?

Could we either add a auto_save_dir parameter which does what I expected, or is
it possible to change the behaviour for save_path, after it's been shipped?

require("codesnap.nvim").setup() didn't work

Hello, amazing plugin 😍, really missing a feature like that for Neovim, however I had issues running the Lua module
this didn't work for me using Lazy as plugin manager,

require("codesnap.nvim").setup({})

but this did

require("codesnap").setup({})

this might be a Lazy only behavior, so feel free to close this issue.

The latest version 1.0 & 1.0.1 install failed

Failed to source /Users/lee/.local/share/nvim/site/lazy/codesnap.nvim/plugin/codesnap.lua

vim/_editor.lua:0: /Users/lee/.config/nvim/init.lua..nvim_exec2() called at /Users/lee/.config/nvim/init.lua:0../Users/lee/.local/share/nvim/site/lazy/codesnap.nvim/plugin/codesnap.lua: Vim(source):E5113: Err
or while calling lua chunk: vim/loader.lua:0: dlopen(/Users/lee/.local/share/nvim/site/lazy/codesnap.nvim/lua/generator.so, 0x0006): tried: '/Users/lee/.local/share/nvim/site/lazy/codesnap.nvim/lua/generator.s
o' (mach-o file, but is an incompatible architecture (have (arm64), need (x86_64h)))
stack traceback:
^I[C]: in function 'error'
^Ivim/loader.lua: in function <vim/loader.lua:0>
^I[C]: in function 'require'
^I...share/nvim/site/lazy/codesnap.nvim/lua/codesnap/init.lua:3: in main chunk
^I[C]: in function 'require'
^I...l/share/nvim/site/lazy/codesnap.nvim/plugin/codesnap.lua:1: in main chunk
^I[C]: in function 'nvim_exec2'
^Ivim/_editor.lua: in function 'cmd'
^I.../share/nvim/site/lazy/lazy.nvim/lua/lazy/core/loader.lua:485: in function <.../share/nvim/site/lazy/lazy.nvim/lua/lazy/core/loader.lua:484>
^I[C]: in function 'xpcall'
^I...al/share/nvim/site/lazy/lazy.nvim/lua/lazy/core/util.lua:113: in function 'try'
^I...
^I.../share/nvim/site/lazy/lazy.nvim/lua/lazy/core/loader.lua:191: in function 'load'
^I.../share/nvim/site/lazy/lazy.nvim/lua/lazy/core/loader.lua:123: in function 'startup'
^I.../.local/share/nvim/site/lazy/lazy.nvim/lua/lazy/init.lua:110: in function 'setup'
^I/Users/lee/.config/nvim/lua/core/pack.lua:135: in function 'load_lazy'
^I/Users/lee/.config/nvim/lua/core/pack.lua:138: in main chunk
^I[C]: in function 'require'
^I/Users/lee/.config/nvim/lua/core/init.lua:160: in function 'load_core'
^I/Users/lee/.config/nvim/lua/core/init.lua:170: in main chunk
^I[C]: in function 'require'
^I/Users/lee/.config/nvim/init.lua:2: in main chunk

stacktrace:

  • vim/_editor.lua:0 in cmd
  • lua/core/pack.lua:135 in load_lazy
  • lua/core/pack.lua:138
  • lua/core/init.lua:160 in load_core
  • lua/core/init.lua:170
  • init.lua:2

The error msg.

Add option to support line numbers

I believe a viable enhancement to this plugin would be addition of the option to show line numbers in the screenshot. It might help when not whole file is screenshotted but rather a section of it. When creating guides online or sharing code snaps with others it helps whomever is reading to orient themselves in the file.

Bug: Version v1.1.10 and upper fail on Mac

Not sure what exactly happens, but from what I can tell, neovim just quits... here is an example...

Screen.Recording.2024-04-11.at.16.42.03.mov

Same does not happen on v1.1.9

Screen.Recording.2024-04-11.at.16.43.06.mov

Configuration:

return {
	{
		"mistricky/codesnap.nvim",
		build = "make",
		version = "v1.1.x",
		config = function()
			require("codesnap").setup({
				mac_window_bar = true,
				title = "CodeSnap.nvim",
				code_font_family = "CaskaydiaCove Nerd Font",
				watermark_font_family = "Pacifico",
				watermark = "",
				bg_theme = "grape",
				breadcrumbs_separator = "/",
				has_breadcrumbs = true,
			})
		end,
	}
}

Notes:

  • This happens on v1.1.11 too
  • macbook: image

Troubleshooting:

  • Restarted the terminal
  • Restarted the PC

Keybind documentation

Can you add your setup for keymaps?

    {
      "<leader>ss",
      function()
        vim.cmd("CodeSnap")
      end,
      desc = "CodeSnap",
      mode = "v",
    },

Currently this doesnt work, I have to manually visually select, then type the command CodeSnap removing the range selectors < and >

If i use the above it will just say "no code selected"

WSL support

Currently using WSL sometimes, would be nice to be able to pass in commands to copy to clipboard, i.e i think to copy to windows clipboard you need something piped like output | clip.exe

Tab indention doesn't look right.

I use tabs for indention and it looks like this.
image

It works fine for spaces.

This is my nvim --version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1692716794

Add: target Linux ARM64

I'm using Fedora Asahi Remix and I'd like to use CodeSnap on Linux ARM64.
There are other problems, maybe I'm doing something wrong:

  • code_font_family = "JetBrainsMono Nerd Font" doesn't work (I have installed it and I use it)
  • mac_window_bar = false doesn't work

This is my config:

local home = os.getenv "HOME"
...
  {
    "mistricky/codesnap.nvim",
    build = "make",
    version = "^1",
    lazy = "true",
    cmd = {
      "CodeSnap",
      "CodeSnapSave",
    },
    config = function()
      require("codesnap").setup {
        title = "CodeSnap.nvim",
        -- code_font_family = "CaskaydiaCove Nerd Font",
        code_font_family = "JetBrainsMono Nerd Font",
        mac_window_bar = false,
        has_breadcrumbs = true,
        bg_theme = "default",
        save_path = home .. "/.snap.png",
        watermark_font_family = "Pacifico",
        watermark = "Matteo Cavestri",
      }
    end,
  },

On x86 I only have that problems.
Here an example:
snap

Thanks all

Add `workspace`

share code snippet to others. workspace is good to show this code blong to some project.

Add support for font weight and type

I have very specific font specifications in Kitty terminal, it would be really cool to be able to use those same settings for the fonts. Right now if you choose a font family that only has Thin weights or Italics to try to force it to use that font, it just returns a default sans font.

Ideally I would like something like:

code_font_family = "EllographCF Nerd Font Thin"
watermark_font_family = "EllographCF Nerd Font Light Italic"

Love this plugin though, fantastic work!

Easier way to detect language type?

Currently doing this:

    {
      "<leader>ss",
      function()
        vim.cmd("CodeSnap " .. vim.bo.filetype)
      end,
      desc = "CodeSnap",
      mode = "v",
    },
    {
      "<leader>sS",
      function()
        vim.cmd("CodeSnapSave " .. vim.bo.filetype)
      end,
      desc = "CodeSnap save to ~/codesnap",
      mode = "v",
    },

Seems to work.. for lua at least, might work for other languages, I guess it depends how the names are matched vs vim.bo.filetype

`CodeSnap` doesn't work whatever i do

Without selecting code, i would like a vim.notify or vim.print instead of WTF type logs
log1 -> happens when i first time try CodeSnap without selection:

Error executing Lua callback: .../NeutronVim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: Vim:Error executing Lua callback: ...hare/NeutronVim/lazy/codesnap.nvim/lua/codesnap/init.lua:31: Please select code which you want to take snapshot first
stack traceback:
	[C]: in function 'error'
	...hare/NeutronVim/lazy/codesnap.nvim/lua/codesnap/init.lua:31: in function 'get_config'
	...hare/NeutronVim/lazy/codesnap.nvim/lua/codesnap/init.lua:49: in function 'copy_into_clipboard'
	.../share/NeutronVim/lazy/codesnap.nvim/plugin/codesnap.lua:4: in function <.../share/NeutronVim/lazy/codesnap.nvim/plugin/codesnap.lua:3>
	[C]: in function 'cmd'
	.../NeutronVim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <.../NeutronVim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>
stack traceback:
	[C]: in function 'cmd'
	.../NeutronVim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <.../NeutronVim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>

log2 -> happens after 1st time of no code selection

Error executing Lua callback: ...hare/NeutronVim/lazy/codesnap.nvim/lua/codesnap/init.lua:31: Please select code which you want to take snapshot first
stack traceback:
	[C]: in function 'error'
	...hare/NeutronVim/lazy/codesnap.nvim/lua/codesnap/init.lua:31: in function 'get_config'
	...hare/NeutronVim/lazy/codesnap.nvim/lua/codesnap/init.lua:49: in function 'copy_into_clipboard'
	.../share/NeutronVim/lazy/codesnap.nvim/plugin/codesnap.lua:4: in function <.../share/NeutronVim/lazy/codesnap.nvim/plugin/codesnap.lua:3>

sometimes with luck [tho i can't paste this anywhere] i get Save snapshot into clipboard successfully
check video:

Kooha-2024-03-17-20-11-04.webm

CodeSnapSave works, but i dont get breadcrumbs in it:
idk

And sometimes, neovim crashes, check video:

Kooha-2024-03-17-20-02-00.webm

@mistricky, my config:

  -- Beautiful CodeSnippet Viewing
  {
    "mistricky/codesnap.nvim",
    build = "make",
    version = "^1",
    lazy = true,
    cmd = { "CodeSnap", "CodeSnapSave" },
    config = function()
      require("codesnap").setup({
        has_breadcrumbs = true,
        bg_theme = "summer",
        save_path = "./idk.png",
      })
    end,
  },

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.