Skip to content

Instantly share code, notes, and snippets.

@844196
Last active August 29, 2015 14:10
Show Gist options
  • Save 844196/4c1dc9a89dd02ece4ebe to your computer and use it in GitHub Desktop.
Save 844196/4c1dc9a89dd02ece4ebe to your computer and use it in GitHub Desktop.
<a href="foo"><img src="bar.jpg" alt="buzz"></a> → [![buzz](bar.jpg)](foo)

Usage

Installation

" add .vimrc
NeoBundle 'gist:844196/4c1dc9a89dd02ece4ebe', {
    \ 'name' : 'Img_to_markdown.vim',
    \ 'script_type' : 'plugin'
    \ }

Setting

" set keymap
nmap <silent><space>im <Plug>(img_to_markdown)

License

Do What The F*ck You Want To Public License Version 2 (WTFPL-2.0)

function! Img_to_markdown()
let url = matchstr(getline("."), 'https\?:\/\/[^ >,;:"\[\]]*')
let img = matchstr(getline("."), 'https\?:\/\/[^ >,;:"\[\]]*\(jpe\?g\|png\|gif\|bmp\)')
let alt = matchstr(getline("."), 'alt="\zs.*\ze"')
call setline(".", "[![" . alt . "](" . img . ")](" . url . ")")
endfunction
nnoremap <silent><Plug>(img_to_markdown) :<C-u>call Img_to_markdown()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment