blob: 51592f09be42693ee770346373e33bd07b8a9a7e [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>
Morton Fox7c930eb2025-02-01 10:28:52 +01006# Last Change: 2025 Feb 01
Luca Saccarolac729d6d2025-01-25 16:07:12 +01007
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
Morton Fox7c930eb2025-02-01 10:28:52 +010021 const user_var = get(g:, 'gx_word', get(g:, 'netrw_gx', '<cfile>'))
Luca Saccarola76680122025-01-29 18:33:46 +010022 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