Codesnap.nvim
๐ธ Snapshot plugin with rich features that can make pretty code snapshots for Neovim
Install / Use
/learn @mistricky/Codesnap.nvimREADME
- ๐ฃMigration
- โจFeatures
- Prerequirements
- Install
- Usage
- Breadcrumbs
- Line number
- Custom background
- Watermark
- Commands
- Configuration
- Contribution
- License
๐ฃMigration
Upgrade from v0.x to v1
If you have installed v0.x before, this chapter will show you what break changes version v1.x introduced.
- The
CodeSnapPreviewOncommand is not supported, if you prefer live-preview, you can pinCodeSnap.nvimversion tov0.0.11to continue using this command. - The
opacityandpreview_titleconfig has been removed from v1.0.0 - The
editor_font_familywas renamed tocode_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.
Upgrade from v1 to v2
CodeSnap.nvim v2 bring a lot of new features and improvements, the most important change is that we rewrote the screenshot generator using CodeSnap, this library makes CodeSnap.nvim faster and more stable than before.
And there is no need to setup Rust environment to compile CodeSnap.nvim anymore, we precompiled the generator shared file for common platforms:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- x86_64-apple-darwin
- aarch64-apple-darwin
- windows-x86_64-msvc
For most cases, you can use CodeSnap.nvim out-of-box without any additional setup. ๐ต
Configuration is completely different between v1 and v2, which is following config.rs in CodeSnap. Which means you can use same configuration in both CodeSnap CLI and CodeSnap.nvim. Click here see what current config looks like.
Windows Support
We are excited to announce that CodeSnap.nvim now supports Windows! ๐, but we don't have enough time to test it on Windows, so if you find any issues on Windows, please let us know by creating an issue.
Prerequirements
- Neovim 0.9.0+
Installation
We recommend using Lazy.nvim to install CodeSnap.nvim, but you can still use another plugin manager you prefer.
Lazy.nvim
{ "mistricky/codesnap.nvim", tag = "v2.0.0" }
Maybe you are CodeSnap.nvim v1 user, you may notice that we remove the
buildoption in v2, because we don't need to compile the Rust code anymore, we precompiled thegeneratorshared file for common platforms, you can find the precompiled files in releases page. So when you first install v2, CodeSnap.nvim will download the precompiled file automatically, it may take a few seconds to download the file, please be patient.
Keymappings
TODO
โจFeatures
Consume Snapshot
There are two ways to consume the snapshot you took using CodeSnap.nvim:
Copy into clipboard
Copy the snapshot directly into clipboard, then you can paste it anywhere you want.
Run CodeSnap command, CodeSnap.nvim will generate a snapshot of the currently selected code and write it into clipboard.
CodeSnap
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
Save the snapshot into a file, you can specify the path where you want to save it
Run CodeSnapSave command, CodeSnap.nvim will generate a snapshot of the currently selected code and save it in the path you specified in config.
CodeSnap.nvim supports saving snapshot in PNG, SVG and HTML format, you can specify the file extension in the path you provided, for example:
CodeSnapSave /path/to/your/snapshot.png
CodeSnapSave /path/to/your/snapshot.svg
CodeSnapSave /path/to/your/snapshot.html
ASCII snapshot
CodeSnap.nvim also supports taking ASCII art snapshot, you can use CodeSnapASCII command to take a snapshot in ASCII format and copy it into clipboard.
This feature is not useful for most cases, but it's FUN and lightweight, if you want to paste your code in somewhere like comment, ASCII snapshot may be a good choice.
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ codesnap.nvim/lua/codesnap/config.lua โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 24 local code_content = { โ
โ 25 content = code, โ
โ 26 start_line_number = start_line_number, โ
โ 27 file_path = get_file_path(static.config.show_workspace), โ
โ 28 } โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
As you can see, the ASCII snapshot is just a plain text, without any background, line number, watermark, etc. But it still has key information like code content, line number and file path, which can be useful if someone want to know where the code is from.
Really hope you like this feature! ๐ค
Highlight code block
CodeSnap allows you to take code snapshots with highlights code blocks, we provide two commands for this scenario:
CodeSnapHighlight # Take code snapshot with highlights code blocks and copy it into the clipboard
CodeSnapSaveHighlight # Take code snapshot with highlights code blocks and save it somewhere
How to use
For take a code snapshot with highlights code blocks and save it somewhere. First you need to select code which you want to snapshot, then enter the command CodeSnapSaveHighlight to open a window show you the selected code which from previous step, now you can select code which you want to highlight (if any - you can use these without actually highlighting anything), finally press the Enter key, CodeSnap will generate a snapshot with highlight blocks and save it in save_path.

Breadcrumbs
Breadcrumbs are really useful tool to display the current snapshot file path, you can enable it by setting breadcrumbs.enable to true:
require("codesnap").setup({
-- ...
snapshot_config = {
-- ...
code_config = {
breadcrumbs = {
enable = true,
