ellisonleao/carbon-now.nvim

github github
snippet
star 43
stars
alert-circle 1
open issues
users 1
subscribers
git-branch 0
forks
CREATED

2022-02-22

UPDATED

3 months ago


Requirements

Neovim 0.6 or higher

Installing

Using your preferred plugin manager, add:

'ellisonleao/carbon-now.nvim'

Example with packer:

use {"ellisonleao/carbon-now.nvim", config = function() require('carbon-now').setup() end}

Configuration and customization

The plugin comes with the following default configs:

local defaults = {
  base_url = "https://carbon.now.sh/",
  open_cmd = "xdg-open",
  options = {
    theme = "monokai",
    window_theme = "none",
    font_family = "Hack",
    font_size = "18px",
    bg = "gray",
    line_numbers = true,
    line_height = "133%",
    drop_shadow = false,
    drop_shadow_offset_y = "20px",
    drop_shadow_blur = "68px",
    width = "680",
    watermark = false,
  },
}

You can override it in setup() function. Example:

local carbon = require('carbon-now')
carbon.setup({
  options = {
    theme = "solarized",
    font_family = "Monoid",
  }
})

Generating snippets from visual selection

Adding a custom mapping for generating a new snippet is really easy

-- nvim 0.7.x
vim.keymap.set("v", "<leader>cn", function() require('carbon-now').create_snippet() end, { noremap = true, silent = true})

-- nvim 0.6.x
vim.api.nvim_set_keymap("v", "<leader>cn", "<Cmd>CarbonNow<CR>", { noremap = true, silent = true})

Generating snippets from github gists

In lua you can call:

:lua require('carbon-now').create_snippet_from_gist('<GIST_ID>')

But if you preferer a vim command, just call

:CarbonNowGist GIST_ID

Changing default open in browser command

Example: Opening snippet in google-chrome

require('carbon-now').setup({open_cmd = "google-chrome"})