DEV Community

gokayburuc.dev
gokayburuc.dev

Posted on

Sharing code as an image directly from Neovim

Carbon-Now.nvim

Carbon-now

Sharing code via Neovim has become easier than ever. Now you can share your codes as photos by simply copying them.

You can get information about the configurations from the following github address:

https://github.com/ellisonleao/carbon-now.nvim

If you are using the Lazy package installer, you can easily share it with the configurations I shared below. All you have to do is personalize these settings according to your wishes.

Image description

First, let's look at where these settings come from. When you click on the settings icon on the Carbon.now.sh web page, the names of the settings will appear.

Image description

When you change the values here, you will see a change in the relevant option value in the page URL.

Image description

SampleURL:

https://carbon.now.sh/?bg=midnightblue&t=verminal&wt=boxy&l=lua&width=680&ds=false&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=true&fl=1&fm=Monoid&fs=18px&lh=133%25&si=false&es=2x&wm=false&code=%2509print%28%27hello%2520World%21%27%29&tb=Made%2520with%2520carbon-now.nvim
Enter fullscreen mode Exit fullscreen mode

when we parsed this URL using freeformatter.com HTML Query String looks like this:


-Query String-
'bg':   midnightblue
't':    verminal
'wt':   boxy
'l':    lua
'width':    680
'ds':   false
'dsyoff':   20px
'dsblur':   68px
'wc':   true
'wa':   true
'pv':   56px
'ph':   56px
'ln':   true
'fl':   1
'fm':   Monoid
'fs':   18px
'lh':   133%
'si':   false
'es':   2x
'wm':   false
'code': %09print('hello%20World!')
'tb':   Made%20with%20carbon-now.nvim


Enter fullscreen mode Exit fullscreen mode

This means when we change bg value background changes. You can compare remains if you desire. Whatever, in our configuration parameters changes these values.

    {
        "ellisonleao/carbon-now.nvim",
        lazy = true,
        cmd = "CarbonNow",
        config = function()
            local carbon = require("carbon-now")
            carbon.setup({
                open_cmd  = "chromium-browser",
                base_url = "https://carbon.now.sh/",
                options = {
                    font_family = "Monoid",
                    theme = "verminal",
                    bg = "midnightblue",
                    drop_shadow = true, -- true, false 
                    drop_shadow_blur = "68px",
                    drop_shadow_offset_y = "20px",
                    font_size = "18px",
                    line_height = "133%",
                    line_numbers = true, -- true,false 
                    titlebar = "@gokayburuc with carbon-now.nvim",
                    watermark = false, -- true, false 
                    window_theme = "boxy", -- sharp, none, boxy, bw 
                },
            })
        end,
    },

Enter fullscreen mode Exit fullscreen mode

I'm using chromium-browser so i changed open_cmd with this value. And I changed titlebar option with my own message.

Usage

Once you have adjusted everything and shut down the Lazy screen, launch the screen you wish to copy. Enter CarbonNow into the command line after selecting the text to copy from this screen in Virtual Mode. With your code, it will take you straight to the carbon.now website. Send your code as a PNG file or tweet it.

That is it!

Top comments (0)