convert.nvim
February 10, 2025 ยท View on GitHub
https://github.com/user-attachments/assets/46320296-58c1-408c-9fd5-e3ee757d9288
Dependencies
- nui.nvim: UI Components
Features
- Convert css units with one simple command
- Base font supported for accurate rem conversion
- Convert all in a selection or entire buffer
Installation:
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
}
Commands:
| 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) |
Usage
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
Supported Conversions
Size Units ๐
| Unit | Description |
|---|---|
px | Pixels |
rem | Relative to root element |
cm | Centimeters |
in | Inches |
mm | Millimeters |
pt | Points |
pc | Picas |
Color Formats ๐จ
| Format | Description |
|---|---|
rgb | Red-Green-Blue |
hex | Hexadecimal color code |
hsl | Hue-Saturation-Lightness |
Number Systems ๐ข (Experimental)
- Defined with respective prefix: 0b, 0x, 0o
| Format | Description |
|---|---|
bin | Binary |
hexadecimal | Hexadecimal |
octal | Octal |