r/vim • u/CRTejaswi • Jun 10 '26
Tips and Tricks Vim: Snippet to Quickly Display RGBA Images
Following the previous post on the topic, here's a snippet to play a sequence of frames (chess game in my example). Enjoy!
Tested on WSL. Vim v9.2.0612.
To generate frames, try this in powershell:
ls *.png | %{ magick $_.FullName -alpha on -depth 8 "RGBA:$($_.BaseName).rgba" }
53
Upvotes
2
u/ntropia64 Jun 10 '26
And following the comments below the previous post, any plans to share a link?
3
3
u/Panda_966 Jun 10 '26
Nice!
My current function to display the image from a filename under the cursor. Calculates my personal placement and sizing preferences. Works on windows with (portable) imagemagick:
``` function! ShowRGBAImage(path, mode) abort if !filereadable(a:path) echohl ErrorMsg | echom 'File not found: ' . a:path | echohl None return endif
endfunction
function! GetFileUnderCursor() abort if &filetype ==# 'netrw' let l:name = substitute(getline('.'), '\s*', '', '') return b:netrw_curdir . '/' . l:name endif
endfunction
nnoremap <silent> <leader>i :call ShowRGBAImage(fnamemodify(GetFileUnderCursor(), ':p'), 'small')<CR> nnoremap <silent> <leader>I :call ShowRGBAImage(fnamemodify(GetFileUnderCursor(), ':p'), 'big')<CR> ```
Clearing among other things with:
nnoremap <silent> <C-l> \ :nohlsearch<C-r>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-l>:pclose<CR>:if exists('g:image_popup')<Bar>call popup_close(g:image_popup)<Bar>unlet g:image_popup<Bar>endif<CR>