ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Paste​Image

by shivamsupr ST4 Mac New

Paste clipboard images into Sublime Text with inline preview (macOS only)

Details

  • 1.0.2
  • github.​com
  • github.​com
  • 3 weeks ago
  • 51 minutes ago
  • 51 minutes ago

Installs

  • Total 0
  • Win 0
  • Mac 0
  • Linux 0
Nov 11 Nov 10 Nov 9 Nov 8 Nov 7 Nov 6 Nov 5 Nov 4 Nov 3 Nov 2 Nov 1 Oct 31 Oct 30 Oct 29 Oct 28 Oct 27 Oct 26 Oct 25 Oct 24 Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28
Windows 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Mac 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

PasteImage

macOS only. Sublime Text 4 plugin. Paste an image from the clipboard into any file, and see it inline.

Works on macOS only. It uses pngpaste to read the clipboard and sips to read image sizes. On Linux or Windows the commands are disabled and show a message. Pull requests that add other platforms are welcome.

  • Run PasteImage: Paste Image from Clipboard from the command palette, or bind a key (see below). The image is saved as a PNG and a link is inserted at the cursor. Markdown files get ![](assets/note-1.png). Other files get the path.
  • Run PasteImage: Toggle Inline Preview to toggle inline previews of every image link in the file. Previews update as you edit, and show on their own when you open a file that has image links.
  • If the clipboard has no image, the paste command does a normal text paste.

Install

  1. Install pngpaste:

    brew install pngpaste

  2. Install the plugin:

    • Package Control: Package Control: Install Package → PasteImage
    • Manual: clone this repo into your Packages folder:

      cd “$HOME/Library/Application Support/Sublime Text/Packages” git clone https://github.com/shivamsupr/PasteImage.git

Where images go

By default, images are saved next to the file in an assets/ folder, and the link is relative. Unsaved buffers use ~/Downloads/sublime-paste with an absolute link.

To save every image in one place instead, set save_dir:

Error: language “jsonc” is not supported
// Preferences > Package Settings > PasteImage > Settings
{
    "save_dir": "~/Pictures/pasted"
}

Settings

Setting Default What it does
save_dir "" Fixed folder for all images. Empty means next to the file.
assets_dir "assets" Folder name next to the file when save_dir is empty.
fallback_dir "~/Downloads/sublime-paste" Folder for unsaved buffers.
markdown_template "![]({path})" Text inserted in markdown files.
plain_template "{path}" Text inserted in other files.
fallback_to_text_paste true Normal paste when there is no image.
preview_after_paste true Show the preview right after a paste.
auto_preview true Show previews when a file is opened.
preview_max_width 600 Scale down wider previews (pixels).
pngpaste_path "" Full path to pngpaste. Empty means auto-detect.

Templates accept {path} (the link) and {name} (the file name).

Key bindings

The package ships no active key bindings, so it cannot clash with other packages. To add them, open Preferences > Package Settings > PasteImage > Example Key Bindings and copy this into the right-hand pane:

[
    { "keys": ["super+ctrl+shift+v"], "command": "paste_image" },
    { "keys": ["super+ctrl+p"], "command": "paste_image_preview" }
]

Troubleshooting

Open the console with Ctrl+</kbd>. Lines that start with [PasteImage]show whichpngpaste` binary ran and its exit code.

  • "pngpaste not found": install it, or set pngpaste_path.
  • Text pasted instead of an image: the clipboard had no image. On macOS, Cmd+Shift+4 saves a screenshot to a file. Add Ctrl to copy it to the clipboard instead.
  • The image link appears, then old text replaces it: another app also acts on the shortcut. Clipboard managers do this: they swap the clipboard to an older item, send Cmd+V, and swap it back. Find the app that owns the key, or rebind paste_image to a free key. Set "debug": true to see every command that reaches the view in the console.

Requirements

  • Sublime Text 4
  • macOS (uses pngpaste and sips)

License

MIT