|
1 | 1 | # convert.nvim |
2 | 2 |
|
3 | | -https://github.com/user-attachments/assets/46129dd1-35b0-41ce-a1d8-ead1922d8af4 |
| 3 | +https://github.com/user-attachments/assets/46320296-58c1-408c-9fd5-e3ee757d9288 |
4 | 4 |
|
5 | 5 | ## Dependencies |
6 | 6 | - [nui.nvim](https://github.com/MunifTanjim/nui.nvim): UI Components |
7 | 7 |
|
8 | 8 | ## Features |
9 | 9 | - Convert css units with one simple command |
10 | | -- track base font size on save to convert px to rems accurately (Single file support only) |
| 10 | +- Base font supported for accurate rem conversion |
| 11 | +- Convert all in a selection or entire buffer |
11 | 12 |
|
12 | 13 | ## Installation: |
13 | 14 | Use your favourite plugin manager |
14 | 15 |
|
15 | 16 | - Lazy: |
16 | 17 | ```lua |
17 | 18 | return { |
18 | | - 'cjodo/convert.nvim', |
19 | | - dependencies = { |
20 | | - 'MunifTanjim/nui.nvim' |
21 | | - }, |
22 | | - keys = { |
23 | | - { "<leader>cn", "<cmd>ConvertFindNext<CR>", desc = "Find next convertable unit" }, |
24 | | - { "<leader>cc", "<cmd>ConvertFindCurrent<CR>", desc = "Find convertable unit in current line" }, |
25 | | - { "<leader>ca", "<cmd>ConvertAll<CR>", desc = "Convert all of a specified unit" }, |
26 | | - }, |
| 19 | + 'cjodo/convert.nvim', |
| 20 | + dependencies = { |
| 21 | + 'MunifTanjim/nui.nvim' |
| 22 | + }, |
| 23 | + keys = { |
| 24 | + { "<leader>cn", "<cmd>ConvertFindNext<CR>", desc = "Find next convertable unit" }, |
| 25 | + { "<leader>cc", "<cmd>ConvertFindCurrent<CR>", desc = "Find convertable unit in current line" }, |
| 26 | + -- Add "v" to enable converting a selected region |
| 27 | + { "<leader>ca", "<cmd>ConvertAll<CR>", mode = {"n", "v"}, desc = "Convert all of a specified unit" }, |
| 28 | + }, |
27 | 29 | } |
| 30 | +``` |
| 31 | +- Packer: |
| 32 | +```lua |
| 33 | +use { |
| 34 | + 'cjodo/convert.nvim', |
| 35 | + requires = { 'MunifTanjim/nui.nvim' }, |
| 36 | + config = function() |
| 37 | + require('convert').setup() |
| 38 | + vim.keymap.set('n', '<leader>cn', '<cmd>ConvertFindNext<CR>', { desc = 'Find next convertible unit' }) |
| 39 | + vim.keymap.set('n', '<leader>cc', '<cmd>ConvertFindCurrent<CR>', { desc = 'Find convertible unit in current line' }) |
| 40 | + vim.keymap.set({ 'n', 'v' }, '<leader>ca', '<cmd>ConvertAll<CR>', { desc = 'Convert all of a specified unit' }) |
| 41 | + end |
| 42 | +} |
| 43 | + |
28 | 44 | ``` |
29 | 45 | ## Commands: |
30 | 46 |
|
31 | 47 | | Command | Description | |
32 | 48 | |----------------------|---------------------------------------------------------------------------| |
33 | 49 | | :ConvertFindNext | Finds the next convertible unit | |
34 | 50 | | :ConvertFindCurrent | Finds the convertible unit in the current line (starting from cursor) | |
35 | | -| :ConvertAll | Converts all instances of a given unit to another | |
| 51 | +| :ConvertAll | Converts all instances in a buffer or visual mode selection of one unit to another of the same type (size, color) | |
36 | 52 |
|
37 | 53 | ## Usage |
38 | 54 | You can choose you're own custom keys for the ui menu |
39 | 55 |
|
40 | 56 | ```lua |
41 | | - config = function() |
| 57 | +config = function() |
42 | 58 | local convert = require('convert') |
43 | 59 | -- defaults |
44 | 60 | convert.setup({ |
45 | | - keymaps = { |
46 | | - focus_next = { "j", "<Down>", "<Tab>" }, |
47 | | - focus_prev = { "k", "<Up>", "<S-Tab>" }, |
48 | | - close = { "<Esc>", "<C-c>", 'qq' }, |
49 | | - submit = { "<CR>", "<Space>" }, |
50 | | - } |
| 61 | + keymaps = { |
| 62 | + focus_next = { "j", "<Down>", "<Tab>" }, |
| 63 | + focus_prev = { "k", "<Up>", "<S-Tab>" }, |
| 64 | + close = { "<Esc>", "<C-c>", 'qq' }, |
| 65 | + submit = { "<CR>", "<Space>" }, |
| 66 | + }, |
| 67 | + modes = { "color", "size", "numbers" } -- available conversion modes |
51 | 68 | }) |
52 | | - end |
| 69 | +end |
53 | 70 |
|
54 | 71 | ``` |
| 72 | +## Supported Conversions |
| 73 | + |
| 74 | +### Size Units 📏 |
| 75 | + |
| 76 | +| Unit | Description | |
| 77 | +|------|------------| |
| 78 | +| `px` | Pixels | |
| 79 | +| `rem` | Relative to root element | |
| 80 | +| `cm` | Centimeters | |
| 81 | +| `in` | Inches | |
| 82 | +| `mm` | Millimeters | |
| 83 | +| `pt` | Points | |
| 84 | +| `pc` | Picas | |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +### Color Formats 🎨 |
| 89 | + |
| 90 | +| Format | Description | |
| 91 | +|--------|------------| |
| 92 | +| `rgb` | Red-Green-Blue | |
| 93 | +| `hex` | Hexadecimal color code | |
| 94 | +| `hsl` | Hue-Saturation-Lightness | |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +### Number Systems 🔢 (Experimental) |
| 99 | +- Defined with respective prefix: 0b, 0x, 0o |
| 100 | + |
| 101 | +| Format | Description | |
| 102 | +|-------------|------------| |
| 103 | +| `bin` | Binary | |
| 104 | +| `hexadecimal` | Hexadecimal | |
| 105 | +| `octal` | Octal | |
| 106 | + |
0 commit comments