Skip to content

Instantly share code, notes, and snippets.

@chemzqm chemzqm/open.vim
Last active Jan 16, 2016

Embed
What would you like to do?
Open url in vim
" ============================================================================
" Description: Open url under cursor or git repository of a module
" Author: Qiming Zhao <chemzqm@gmail.com>
" Licence: Vim licence
" Version: 0.1
" Last Modified: January 16, 2016
" ============================================================================
if exists('did_open_loaded') || v:version < 700
finish
endif
let did_open_loaded = 1
function! s:Open()
let line = getline('.')
" match url
let url = matchstr(line, '\vhttps?:\/\/[^)''" ]+')
if !empty(url)
call s:system('open '. url)
else
let mail = matchstr(line, '\v([A-Za-z0-9_\.-]+)\@([A-Za-z0-9_\.-]+)\.([a-z\.]+)')
if !empty(mail)
call s:system('open mailto:' . mail)
endif
endif
endfunction
function! s:system(cmd)
let output = system(a:cmd)
if v:shell_error && output !=# ""
echohl Error | echon output | echohl None
endif
endfunction
nnoremap <leader>o :call <SID>Open()<cr>
imap <2-LeftMouse> <C-o>:call <SID>Open()<CR>
nmap <2-LeftMouse> :call <SID>Open()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.