Skip to content

Instantly share code, notes, and snippets.

@andreadev-it
Created April 10, 2022 20:20
Show Gist options
  • Save andreadev-it/924924928625740191b9f0c4b26e1d19 to your computer and use it in GitHub Desktop.
Save andreadev-it/924924928625740191b9f0c4b26e1d19 to your computer and use it in GitHub Desktop.
How to view images in neovim

This is a basic guide that allows you to see images previews inside of neovim. The image will be generated via timg and the output will be shown inside the vim buffer.

Prerequisites

First, you should have timg installed on your system:

sudo snap install timg

Code inside init.lua (or init.vim)

Just set up this autocommand:

vim.cmd([[
  au BufEnter *.jpg,*.png terminal timg %
]])

If you are using vim script, you should remove the first and last line.

This code will create an auto command that will run whenever a Buffer is shown. Use it just to preview images from time to time, since it will reload the preview every time you enter the buffer and that might be a little heavy on the system.

I'm new to neovim scripting, so if you see a problem or know how to improve it, please send me a message 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment