Skip to content
Browse files

Make gx work on urls in Markdown.

This also allows you to highlight some text and use ``gx`` to open it.
  • Loading branch information...
1 parent a164574 commit 773a9db7275bc5e880b0633ec78e8b92254f267f @jszakmeister committed Mar 12, 2013
Showing with 36 additions and 0 deletions.
  1. +36 −0 user/jszakmeister/vimrc-after.vim
View
36 user/jszakmeister/vimrc-after.vim
@@ -292,6 +292,42 @@ endif
let Grep_Xargs_Options = '-0'
" -------------------------------------------------------------
+" Netrw
+" -------------------------------------------------------------
+
+let g:netrw_nogx = 1
+
+function! SmartOpen()
+ if mode() ==# 'n'
+ let uri = expand("<cWORD>")
+ if match(uri, "://")
+ let uri = expand("<cfile>")
+ endif
+ else
+ let uri = s:get_selected_text()
+ endif
+
+ call netrw#NetrwBrowseX(uri, 0)
+endfunction
+command! -bar SmartOpen call SmartOpen()
+
+" Get selected text in visual mode.
+function! s:get_selected_text()
+ let save_z = getreg('z', 1)
+ let save_z_type = getregtype('z')
+
+ try
+ normal! gv"zy
+ return @z
+ finally
+ call setreg('z', save_z, save_z_type)
+ endtry
+endfunction
+
+nmap gx :SmartOpen<CR>
+vmap gx :SmartOpen<CR>
+
+" -------------------------------------------------------------
" VimClojure
" -------------------------------------------------------------

0 comments on commit 773a9db

Please sign in to comment.
Something went wrong with that request. Please try again.