Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Neovim
OpenUrl.nvim
Commits
52cfee8c
Verified
Commit
52cfee8c
authored
Nov 12, 2017
by
Marco Kellershoff
🤸
Browse files
Check if it's a valid URL, otherwise (optional) fallback to investigate.vim
parent
912ba389
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
52cfee8c
...
...
@@ -12,6 +12,9 @@ Here's a quick example:
```
vim
" OpenUrl.nvim binding
nnoremap
<
leader
>
e
:
call
OpenUrl#UnderCursor
()<
CR
>
nnoremap
<
leader
>
q
:
call
OpenUrl#UnderCursor
()<
CR
>
" Use keith/investigate.vim as a fallback, if it's not an URL
let
g:loaded_OpenUrl_DarkInvestigate
=
1
```
plugin/OpenUrl.vim
View file @
52cfee8c
...
...
@@ -5,17 +5,24 @@ let g:loaded_OpenUrl = 1
function
!
OpenUrl#UnderCursor
()
let
s:url
=
OpenUrl#GetWordUnderCursor
()
if
has
(
'win16'
)
||
has
(
'win32'
)
||
has
(
'win64'
)
exe
'!start cmd /cstart /b '
.
s:url
.
''
elseif
has
(
'mac'
)
||
has
(
'macunix'
)
||
has
(
'gui_macvim'
)
exe
'silent !open "'
.
s:url
.
'"'
let
s:is_url
=
OpenUrl#IsUrl
(
s:url
)
if
s:is_url
==
1
call
OpenUrl#WithDefaultBrowser
(
s:url
)
else
exe
'silent !xdg-open "'
.
s:url
.
'"'
call
OpenUrl#PassToDarkInvestigate
()
endif
endfunction
function
!
OpenUrl#PassToDarkInvestigate
()
let
s:url
=
OpenUrl#GetWordUnderCursor
()
if
exists
(
'g:loaded_OpenUrl_DarkInvestigate'
)
call
investigate#Investigate
()
else
echo
'No valid URL found: '
.
s:url
endif
redraw
!
endfunction
function
!
OpenUrl#
Open
(
url
)
function
!
OpenUrl#
WithDefaultBrowser
(
url
)
if
has
(
'win16'
)
||
has
(
'win32'
)
||
has
(
'win64'
)
exe
'!start cmd /cstart /b '
.
a:url
.
''
elseif
has
(
'mac'
)
||
has
(
'macunix'
)
||
has
(
'gui_macvim'
)
...
...
@@ -36,6 +43,15 @@ function! OpenUrl#OpenWith(app, file)
endif
endfunction
function
!
OpenUrl#IsUrl
(
str
)
let
s:url
=
matchstr
(
a:str
,
'[a-z]*:\/\/[^ >,;]*'
)
if
empty
(
s:url
)
return
0
else
return
1
endif
endfunction
function
!
OpenUrl#GetWordUnderCursor
()
return
expand
(
"<cWORD>"
)
endfunction
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment