Compare commits
10 Commits
f927a29330
...
5114853ed8
| Author | SHA1 | Date | |
|---|---|---|---|
|
5114853ed8
|
|||
|
577f26bfdd
|
|||
|
6956c227ca
|
|||
|
30e9026d51
|
|||
|
68aac990e3
|
|||
|
6a84d739e1
|
|||
|
d3f814cca8
|
|||
|
f65f5ed530
|
|||
|
274d7ef476
|
|||
|
d29ebec0a8
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
p.vim
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) [year] [Your Name]
|
||||
Copyright (c) 2025 Syed
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
49
README.md
49
README.md
@@ -36,6 +36,7 @@ To use PicVim, simply open an image file in Neovim and the image will be display
|
||||
- Rotate the image with configurable keybindings.
|
||||
- Pan the image using arrow keys or specific keybindings.
|
||||
- Automatically scale and adjust images for optimal viewing.
|
||||
- Configure keybindings and image types to work with your liking.
|
||||
|
||||
|
||||
## ⚙️ Installation
|
||||
@@ -64,6 +65,13 @@ You can set custom keymaps using the `keymap` option.
|
||||
|
||||
```lua
|
||||
require'picvim'.setup({
|
||||
filetypes = { -- Default filetypes
|
||||
"png", -- For now only these are supported:
|
||||
"jpg", -- > PNG, JPG, JPEG, GIF, BMP
|
||||
"jpeg",
|
||||
"gif", -- No need to set these if you want to
|
||||
"bmp", -- support all of these image formats.
|
||||
}
|
||||
keymap = { -- Default keymaps
|
||||
move_left = { "<Left>", "h" }, -- Pan left
|
||||
move_right = { "<Right>", "l" }, -- Pan right
|
||||
@@ -81,25 +89,36 @@ require'picvim'.setup({
|
||||
|
||||
## 🛠️ Autocommands
|
||||
|
||||
The plugin automatically activates for image files (.png, .jpg, .jpeg, .gif, .bmp) upon opening. It sets the buffer to a "non-file" type to display the image correctly.
|
||||
The plugin automatically activates for image files (.png, .jpg, .jpeg, .gif, .bmp) (configured in the `filetypes` option) upon opening. It sets the buffer to a "non-file" type to display the image correctly.
|
||||
|
||||
## ⌨️ Default Keybindings
|
||||
## ⌨️ Default Keymaps
|
||||
|
||||
h, Left Arrow – Pan left.
|
||||
l, Right Arrow – Pan right.
|
||||
j, Down Arrow – Pan down.
|
||||
k, Up Arrow – Pan up.
|
||||
=, + – Zoom in.
|
||||
-, _ – Zoom out.
|
||||
t – Rotate clockwise (30 degrees).
|
||||
T – Rotate counterclockwise (30 degrees).
|
||||
o – Reset image position and rotation.
|
||||
r – Rerender the image.
|
||||
| Options within `keymap` | Default Value | Description |
|
||||
|-----------------------------|-----------------------|--------------------------|
|
||||
| `move_left` | `{"<Left>", "h"}` | Moves the image left |
|
||||
| `move_right` | `{"<Right>", "l"}` | Moves the image right |
|
||||
| `move_down` | `{"<Down>", "j"}` | Moves the image down |
|
||||
| `move_up` | `{"<Up>", "k"}` | Moves the image up |
|
||||
| `zoom_in` | `{"=", "+"}` | Zooms into the image |
|
||||
| `zoom_out` | `{"-", "_"}` | Zooms out of the image |
|
||||
| `rotate_clockwise` | `"t"` | Rotates clockwise |
|
||||
| `rotate_counterclockwise` | `"T"` | Rotates counterclockwise |
|
||||
| `reset` | `"o"` | Resets the image |
|
||||
| `rerender` | `"r"` | Rerenders the image |
|
||||
|
||||
## Filetypes
|
||||
|
||||
Defaults to:
|
||||
- `{ "png", "jpg", "jpeg", "gif", "bmp" }`
|
||||
|
||||
- You can set custom filetypes using the `filetypes` option.
|
||||
- The value must be a table of strings that includes the file extension for the image.
|
||||
- Filetypes not in the default list will not work (They'll be ignored).
|
||||
|
||||
## 📦 Dependencies
|
||||
|
||||
- `ImageMagick` for image manipulation.
|
||||
- `Neovim` 0.5.0 or higher.
|
||||
- `Neovim` (Obviously).
|
||||
- `Kitty` for displaying the image.
|
||||
|
||||
## TODO:
|
||||
@@ -109,7 +128,9 @@ The plugin automatically activates for image files (.png, .jpg, .jpeg, .gif, .bm
|
||||
- [x] Support image rotation.
|
||||
- [x] Add support for non-png raster images.
|
||||
- [x] Make Keybinds configurable.
|
||||
- [x] Add config for filetypes to work with.
|
||||
- [ ] Add support for svg files.
|
||||
- [ ] Add config for filetypes to work with.
|
||||
- [ ] Add PDF viewer.
|
||||
- [ ] Add support for gif animations.
|
||||
- [ ] Expose functions to handle the images.
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@ PicVim is a Neovim plugin that allows you to view and manipulate images in a
|
||||
Neovim buffer. It also provides configurable key mappings for image navigation
|
||||
and manipulation.
|
||||
>lua
|
||||
require'picvim'.setup({ keymap = { ... } })
|
||||
require'picvim'.setup({ filetypes = { ... }, keymap = { ... } })
|
||||
<
|
||||
==============================================================================
|
||||
|
||||
2. *INSTALLATION*
|
||||
|
||||
Use your preferred plugin manager, e.g., with lazy.nvim:
|
||||
Use your preferred plugin manager, e.g., with `lazy.nvim`:
|
||||
>lua
|
||||
{
|
||||
'Toprun123/PicVim',
|
||||
@@ -40,6 +40,13 @@ Use your preferred plugin manager, e.g., with lazy.nvim:
|
||||
The plugin can be configured using:
|
||||
>lua
|
||||
require'picvim'.setup({
|
||||
filetypes = { -- Default filetypes
|
||||
"png", -- For now only these are supported:
|
||||
"jpg", -- > PNG, JPG, JPEG, GIF, BMP
|
||||
"jpeg",
|
||||
"gif", -- No need to set these if you want to
|
||||
"bmp", -- support all of these image formats.
|
||||
}
|
||||
keymap = {
|
||||
move_left = { "<Left>", "h" }, -- Pan left
|
||||
move_right = { "<Right>", "l" }, -- Pan right
|
||||
@@ -69,6 +76,13 @@ The plugin can be configured using:
|
||||
│ `rerender` │ `"r"` │ Rerenders the image │
|
||||
└─────────────────────────┴──────────────────┴──────────────────────────┘
|
||||
|
||||
Filetypes defaults to:
|
||||
- `{ "png", "jpg", "jpeg", "gif", "bmp" }`
|
||||
|
||||
- You can set custom filetypes using the `filetypes` option.
|
||||
- The value must be a table of strings.
|
||||
- Filetypes not in the default list will not work (They'll be ignored).
|
||||
|
||||
==============================================================================
|
||||
|
||||
4. *USAGE*
|
||||
@@ -87,4 +101,4 @@ To view this help file inside Neovim, use:
|
||||
:h picvim
|
||||
<
|
||||
==============================================================================
|
||||
vim:tw=78:ts=4:ft=help:norl:ft=help
|
||||
vim:tw=78:ts=4:ft=help:norl
|
||||
|
||||
@@ -12,6 +12,30 @@ if not uv then
|
||||
uv = vim.loop
|
||||
end
|
||||
|
||||
-- Lines 15-37 from http://lua-users.org/wiki/BaseSixtyFour
|
||||
local ba = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
local function enc(data)
|
||||
return (
|
||||
(data:gsub(".", function(x)
|
||||
local r, b = "", x:byte()
|
||||
for i = 8, 1, -1 do
|
||||
r = r .. (b % 2 ^ i - b % 2 ^ (i - 1) > 0 and "1" or "0")
|
||||
end
|
||||
return r
|
||||
end) .. "0000"):gsub("%d%d%d?%d?%d?%d?", function(x)
|
||||
if #x < 6 then
|
||||
return ""
|
||||
end
|
||||
local c = 0
|
||||
for i = 1, 6 do
|
||||
c = c + (x:sub(i, i) == "1" and 2 ^ (6 - i) or 0)
|
||||
end
|
||||
return ba:sub(c + 1, c + 1)
|
||||
end) .. ({ "", "==", "=" })[#data % 3 + 1]
|
||||
)
|
||||
end
|
||||
-- End of code from http://lua-users.org/wiki/BaseSixtyFour
|
||||
|
||||
local Image = {}
|
||||
Image.__index = Image
|
||||
|
||||
@@ -41,7 +65,7 @@ function Image:draw(x, y, w, h)
|
||||
end
|
||||
local data = file:read("*all")
|
||||
file:close()
|
||||
local encoded_data = vim.base64.encode(data):gsub("%/", "/")
|
||||
local encoded_data = enc(data)
|
||||
local pos = 1
|
||||
local chunk_size = 4096
|
||||
stdout:write("\27[" .. x + 2 .. ";" .. y + 4 .. "H")
|
||||
@@ -133,8 +157,16 @@ end
|
||||
|
||||
function M.setup(config)
|
||||
local opts = config or {}
|
||||
local allowed_types = { png = true, jpg = true, jpeg = true, gif = true, bmp = true, ico = true }
|
||||
local filetypes = {}
|
||||
for _, ft in ipairs(opts.filetypes or { "png", "jpg", "jpeg", "gif", "bmp", "ico" }) do
|
||||
if allowed_types[ft] then
|
||||
table.insert(filetypes, ft)
|
||||
end
|
||||
end
|
||||
local formatted = "*." .. table.concat(filetypes, ",*.")
|
||||
vim.api.nvim_create_autocmd("BufEnter", {
|
||||
pattern = "*.png,*.jpg,*.jpeg,*.gif,*.bmp",
|
||||
pattern = formatted,
|
||||
callback = function()
|
||||
if not vim.b.img then
|
||||
vim.b.img = Image:new(vim.fn.expand("%:p"))
|
||||
@@ -257,7 +289,7 @@ function M.setup(config)
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_create_autocmd("VimResized", {
|
||||
pattern = "*.png,*.jpg,*.jpeg,*.gif,*.bmp",
|
||||
pattern = formatted,
|
||||
callback = function()
|
||||
if not vim.b.img then
|
||||
vim.b.img = Image:new(vim.fn.expand("%:p"))
|
||||
|
||||
Reference in New Issue
Block a user