blob: 09f5ad2c43fc99e05baa7131af569c6875db6d50 [file] [log] [blame]
Luca Saccarolac729d6d2025-01-25 16:07:12 +01001vim9script
2
3# Vim runtime support library
4#
5# Maintainer: The Vim Project <https://github.com/vim/vim>
Christian Brabandt9301b432025-04-02 19:32:03 +02006# Last Change: 2025 Apr 02
7
8if exists("g:loaded_openPlugin") || &cp
9 finish
10endif
11g:loaded_openPlugin = 1
Luca Saccarolac729d6d2025-01-25 16:07:12 +010012
13import autoload 'dist/vim9.vim'
14
15command -complete=shellcmd -nargs=1 Launch vim9.Launch(trim(<q-args>))
Christian Brabandt9301b432025-04-02 19:32:03 +020016
17# technically, -nargs=1 is correct, but this throws E480: No match
18# when the argument contains a wildchar on Windows
19command -complete=file -nargs=* Open vim9.Open(trim(<q-args>))
Luca Saccarolac729d6d2025-01-25 16:07:12 +010020
21const no_gx = get(g:, "nogx", get(g:, "netrw_nogx", false))
22if !no_gx
Luca Saccarola76680122025-01-29 18:33:46 +010023 def GetWordUnderCursor(): string
24 const url = matchstr(expand("<cWORD>"), '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}\ze[^A-Za-z0-9/]*$')
25 if !empty(url)
26 return url
27 endif
28
Morton Fox7c930eb2025-02-01 10:28:52 +010029 const user_var = get(g:, 'gx_word', get(g:, 'netrw_gx', '<cfile>'))
Luca Saccarola76680122025-01-29 18:33:46 +010030 return expand(user_var)
31 enddef
32
Luca Saccarolac729d6d2025-01-25 16:07:12 +010033 if maparg('gx', 'n') == ""
Luca Saccarola76680122025-01-29 18:33:46 +010034 nnoremap <unique> gx <scriptcmd>vim9.Open(GetWordUnderCursor())<CR>
Luca Saccarolac729d6d2025-01-25 16:07:12 +010035 endif
36 if maparg('gx', 'x') == ""
37 xnoremap <unique> gx <scriptcmd>vim9.Open(getregion(getpos('v'), getpos('.'), { type: mode() })->join())<CR>
38 endif
39endif
40
41# vim: ts=8 sts=2 sw=2 et