Note The author's account has be brought back online, please go use that repository.
Note Outdated Notice:
This repository was re-uploaded because https://github.com/0oAstro/silicon.lua began to 404 recently.
For some reason git would not let me push the existing repository, so I backed up the .git directory and initialized a new repository.
silicon is a lua plugin for neovim to generate beautiful images of code snippet using silicon
recording.mp4
- beautiful images of source code, saved to preferred place.
- copy to clipboard
- Neovim >= 0.6.0
- silicon
Install the plugin with your preferred package manager:
-- Lua
use {
"narutoxy/silicon.lua",
requires = { "nvim-lua/plenary.nvim" },
config = function()
require('silicon').setup({})
end
}
" Vim Script
Plug 'nvim-lua/plenary.nvim'
Plug 'narutoxy/silicon.lua'
lua require('silicon').setup({})
silicon comes with the following defaults:
{
theme = "auto",
output = "SILICON_${year}-${month}-${date}_${time}.png", -- auto generate file name based on time (absolute or relative to cwd)
bgColor = vim.g.terminal_color_5,
bgImage = "", -- path to image, must be png
roundCorner = true,
windowControls = true,
lineNumber = true,
font = "monospace",
lineOffset = 1, -- from where to start line number
linePad = 2, -- padding between lines
padHoriz = 80, -- Horizontal padding
padVert = 100, -- vertical padding
shadowBlurRadius = 10,
shadowColor = "#555555",
shadowOffsetX = 8,
shadowOffsetY = 8,
gobble = false, -- enable lsautogobble like feature
debug = false, -- enable debug output
}
-- Generate image of lines in a visual selection
vim.keymap.set('v', '<Leader>s', function() silicon.visualise_api() end )
-- Generate image of a whole buffer, with lines in a visual selection highlighted
vim.keymap.set('v', '<Leader>bs', function() silicon.visualise_api({to_clip = true, show_buf = true}) end )
-- Generate visible portion of a buffer
vim.keymap.set('n', '<Leader>s', function() silicon.visualise_api({to_clip = true, visible = true}) end )
-- Generate current buffer line in normal mode
vim.keymap.set('n', '<Leader>s', function() silicon.visualise_api({to_clip = true}) end )
Calling silicon.visualise_api
with lua
in command line doesn't work due to lua
not supporting ranges.
This means that the moment you hit enter, you leave visual mode before lua function is called. While this populates two registers, using them doesn't work with "v" mode maps.
A workaround has been implemented, and a shorthand that forces it is available as .visualise_cmdline
:
-
Generate image of lines in a visual selection
lua require('silicon').visualise_cmdline()
-
Generate image of a whole buffer, with lines in a visual selection highlighted
lua require('silicon').visualise_cmdline({to_clip = true, show_buf = true})
-
Generate visible portion of a buffer
lua require('silicon').visualise_cmdline({to_clip = true, visible = true})
-
The default path of image is the current working directory of the editor, but you can change it by
require("silicon").setup({ output = "/home/astro/Pictures/SILICON_$year-$month-$date-$time.png"), })
Autogenerated silicon themes are unaware of dark/light variants. Utility functions had been exposed that allow regenerating theme on demand:
require("silicon.utils").build_tmTheme()
builds a new tmTheme file from current colorschemerequire("silicon.utils").reload_silicon_cache()
callssilicon --build-cache
This lets one regenerate theme when switching background setting or otherwise reloading ColorScheme
:
vim.api.nvim_create_augroup('SiliconRefresh', { clear = true })
vim.api.nvim_create_autocmd({ 'ColorScheme' },
{
group = 'SiliconRefresh',
callback = function()
silicon_utils.build_tmTheme()
silicon_utils.reload_silicon_cache({async = true})
end,
desc = 'Reload silicon themes cache on colorscheme switch',
}
)