Last active
December 22, 2015 09:38
-
-
Save danchoi/6453034 to your computer and use it in GitHub Desktop.
Custom Vim function to open hyperlinks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Easily open hyperlinks in any Vim buffer: | |
| " Place cursor before or at the beginning of a URL that | |
| " begins with http: or https: and press <leader>o | |
| let s:http_link_pattern = 'https\?:[^ >)\]]\+' | |
| let g:browser_command = 'open ' | |
| func! s:find_href() | |
| let res = search(s:http_link_pattern, 'cw') | |
| if res != 0 | |
| let href = matchstr(expand("<cWORD>") , s:http_link_pattern) | |
| return href | |
| end | |
| endfunc | |
| func! s:open_href_under_cursor() | |
| let command = g:browser_command . " '" . shellescape(s:find_href()) . "' " | |
| call system(command) | |
| endfunc | |
| nnoremap <leader>o :call <SID>open_href_under_cursor()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment