Annoying google drive share link issue if you just copy/paste...

Problem

Recently getting more and more lazy to organize images through blog folders. I know it has a lot of neat image caching/optimization features. Link to Google Drive seems to be a convenient way for me sometimes.

Yet, haunted by this issues of converting:

https://drive.google.com/file/d/{ID}/view?usp=sharing

to:

https://drive.google.com/uc?export=view&id={ID}

Solution

Put this in your Ultisnip:

snippet gimg "google image"
![${0:${VISUAL}}](${1:`!v
substitute(getreg("*"), "https://drive.google.com/file/d/\\(.*\\)/view.*", "https://drive.google.com/uc\\?export=view\\&id=\\1", "g")
`})
endsnippet

Then it grab the register/clipboard and return the correct google drive link as markdown image. But it's essentially just vim command. Feel free to tailor the line after !v to your need.

...