blob: c231dc448c26a01504966a3db391e389d1878224 [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>
6# Last Change: 2025 Jan 24
7
8import autoload 'dist/vim9.vim'
9
10command -complete=shellcmd -nargs=1 Launch vim9.Launch(trim(<q-args>))
11command -complete=file -nargs=1 Open vim9.Open(trim(<q-args>))
12
13const no_gx = get(g:, "nogx", get(g:, "netrw_nogx", false))
14if !no_gx
Luca Saccarola76680122025-01-29 18:33:46 +010015 def GetWordUnderCursor(): string
16 const url = matchstr(expand("<cWORD>"), '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}\ze[^A-Za-z0-9/]*$')
17 if !empty(url)
18 return url
19 endif
20
21 const user_var = get(g:, 'gx_word', get(g:, 'netrw_gx', '<cfile>')
22 return expand(user_var)
23 enddef
24
Luca Saccarolac729d6d2025-01-25 16:07:12 +010025 if maparg('gx', 'n') == ""
Luca Saccarola76680122025-01-29 18:33:46 +010026 nnoremap <unique> gx <scriptcmd>vim9.Open(GetWordUnderCursor())<CR>
Luca Saccarolac729d6d2025-01-25 16:07:12 +010027 endif
28 if maparg('gx', 'x') == ""
29 xnoremap <unique> gx <scriptcmd>vim9.Open(getregion(getpos('v'), getpos('.'), { type: mode() })->join())<CR>
30 endif
31endif
32
33# vim: ts=8 sts=2 sw=2 et