Recording.2024-12-25.092710.mp4
- nui.nvim: UI Components
- Convert css units with one simple command
- Base font supported for accurate rem conversion
- Convert all in a selection or entire buffer
Use your favourite plugin manager
- Lazy:
return {
'cjodo/convert.nvim',
dependencies = {
'MunifTanjim/nui.nvim'
},
keys = {
{ "<leader>cn", "<cmd>ConvertFindNext<CR>", desc = "Find next convertable unit" },
{ "<leader>cc", "<cmd>ConvertFindCurrent<CR>", desc = "Find convertable unit in current line" },
-- Add "v" to enable converting a selected region
{ "<leader>ca", "<cmd>ConvertAll<CR>", mode = {"n", "v"}, desc = "Convert all of a specified unit" },
},
}
- Packer:
use {
'cjodo/convert.nvim',
requires = { 'MunifTanjim/nui.nvim' },
config = function()
require('convert').setup()
vim.keymap.set('n', '<leader>cn', '<cmd>ConvertFindNext<CR>', { desc = 'Find next convertible unit' })
vim.keymap.set('n', '<leader>cc', '<cmd>ConvertFindCurrent<CR>', { desc = 'Find convertible unit in current line' })
vim.keymap.set({ 'n', 'v' }, '<leader>ca', '<cmd>ConvertAll<CR>', { desc = 'Convert all of a specified unit' })
end
}
Command | Description |
---|---|
:ConvertFindNext | Finds the next convertible unit |
:ConvertFindCurrent | Finds the convertible unit in the current line (starting from cursor) |
:ConvertAll | Converts all instances in a buffer or visual mode selection of one unit to another of the same type (size, color) |
You can choose you're own custom keys for the ui menu
config = function()
local convert = require('convert')
-- defaults
convert.setup({
keymaps = {
focus_next = { "j", "<Down>", "<Tab>" },
focus_prev = { "k", "<Up>", "<S-Tab>" },
close = { "<Esc>", "<C-c>", 'qq' },
submit = { "<CR>", "<Space>" },
},
modes = { "color", "size", "numbers" } -- available conversion modes
})
end
Unit | Description |
---|---|
px |
Pixels |
rem |
Relative to root element |
cm |
Centimeters |
in |
Inches |
mm |
Millimeters |
pt |
Points |
pc |
Picas |
Format | Description |
---|---|
rgb |
Red-Green-Blue |
hex |
Hexadecimal color code |
hsl |
Hue-Saturation-Lightness |
- Defined with respective prefix: 0b, 0x, 0o
Format | Description |
---|---|
bin |
Binary |
hexadecimal |
Hexadecimal |
octal |
Octal |