snipsssss.mp4
As a fan of sharing snippet blocks of code, I came across an interesting project snips from robherley, none authentication is required to generate a small snippet of code, whenever you want and without limit.
So I thought... why not make a small/dumb plugin for that on my neovim ! In the past I used Gist.vim but the fact that it required authentication and I had to generate a token that was going to be saved on "clear" on my computer... I didn't really like that.
- VIM (>=8 recommended)
- NVIM (>=0.5 recommended)
- Save/upload code snipets from your code editor.
- List/Edit your saved blocks of code.
The simple idea behind this plugin is to:
- get selected rows from current buffer
- save it in a temporary file
- run this command
cat /your-generated-tmp.file | ssh snips.sh
and return output in a new splitted buffer.
-
Using Packer :
use 'Sanix-Darker/snips.nvim'
-
Using Vim-plug :
Plug 'Sanix-Darker/snips.nvim'
Then in your
init.lua
file you can just run :require('snips.nvim').setup() -- this will just make sure the plugin is available -- maybe planing on adding more customisations ? idk...
-
Using Lazy.nvim :
require('snips').setup()
or
return { { "Sanix-Darker/snips.nvim", config = true, cmd = { "SnipsCreate" }, -- optional, make the plugin loads at cmd executed }, }
- IMPORTANT NOTE: You need to etablish a first connection with snips.sh server
by running this example command on the terminal :
echo "Hello world" | ssh snips.sh
Then you can open your nvim. - Select a bunch of lines from your current buffer and use a snips.nvim command.
SnipsList
To open the list of all uploaded/saved snips you have created so far.SnipsCreate
and you have generated/saved a snippet of your code, you're left with the link to share.SnipsCreatePrivate
to create private snips Note: on private mode, with a generated link like : https://snips.sh/f/the-id You can access your private snips code with: $ ssh f:the-id@snips.shSnipsCreateFromRegister
to create a snippet from register.SnipsCreatePrivateFromRegister
to create a snippet from register and save/upload on private.
Those are default values, you can change as your will !
local opts = {
snips_host = "snips.sh", -- in case you deployed your own custom instance
post_behavior = "echo", -- enum: ["echo", "yank", "echo_and_yank"]
to_register = "+", -- yank to
from_register = "+", -- copy from
cat_cmd = "cat", -- can be `bat` or `less`
ssh_cmd = "ssh", -- choose your custom ssh client
}
require("snips.nvim").setup(opts)
If you have some ideas on how to upgrade this plugin i would be happy to read your issues, suggestions, Pull Requests. But for now i will keep it simple since it does what i want it to do for now.