2025-01-25 16:07:12 +01:00
|
|
|
vim9script
|
|
|
|
|
|
|
|
# Vim runtime support library
|
|
|
|
#
|
|
|
|
# Maintainer: The Vim Project <https://github.com/vim/vim>
|
2025-06-22 20:12:16 +02:00
|
|
|
# Last Change: 2025 Jun 22
|
2025-04-02 19:32:03 +02:00
|
|
|
|
|
|
|
if exists("g:loaded_openPlugin") || &cp
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
g:loaded_openPlugin = 1
|
2025-01-25 16:07:12 +01:00
|
|
|
|
|
|
|
import autoload 'dist/vim9.vim'
|
|
|
|
|
2025-06-11 21:10:59 +02:00
|
|
|
command -complete=shellcmd -nargs=1 Launch vim9.Launch(trim(<f-args>))
|
2025-04-02 19:32:03 +02:00
|
|
|
|
2025-06-11 21:10:59 +02:00
|
|
|
# technically, -nargs=1 is correct, but this throws E480: No match
|
2025-04-02 19:32:03 +02:00
|
|
|
# when the argument contains a wildchar on Windows
|
2025-06-11 21:10:59 +02:00
|
|
|
command -complete=file -nargs=* Open vim9.Open(trim(<f-args>))
|
2025-06-04 21:59:01 +02:00
|
|
|
# Use URLOpen when you don't want completion to happen
|
|
|
|
# (or because you want to avoid cmdline-special)
|
2025-06-11 21:10:59 +02:00
|
|
|
command -nargs=1 URLOpen vim9.Open(trim(<f-args>))
|
2025-01-25 16:07:12 +01:00
|
|
|
|
|
|
|
const no_gx = get(g:, "nogx", get(g:, "netrw_nogx", false))
|
|
|
|
if !no_gx
|
2025-01-29 18:33:46 +01:00
|
|
|
def GetWordUnderCursor(): string
|
|
|
|
const url = matchstr(expand("<cWORD>"), '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}\ze[^A-Za-z0-9/]*$')
|
|
|
|
if !empty(url)
|
|
|
|
return url
|
|
|
|
endif
|
|
|
|
|
2025-02-01 10:28:52 +01:00
|
|
|
const user_var = get(g:, 'gx_word', get(g:, 'netrw_gx', '<cfile>'))
|
2025-01-29 18:33:46 +01:00
|
|
|
return expand(user_var)
|
|
|
|
enddef
|
|
|
|
|
2025-01-25 16:07:12 +01:00
|
|
|
if maparg('gx', 'n') == ""
|
2025-06-22 20:12:16 +02:00
|
|
|
nnoremap <Plug>(open-word-under-cursor) <scriptcmd>vim9.Open(GetWordUnderCursor())<CR>
|
|
|
|
nmap gx <Plug>(open-word-under-cursor)
|
2025-01-25 16:07:12 +01:00
|
|
|
endif
|
|
|
|
if maparg('gx', 'x') == ""
|
2025-06-22 20:12:16 +02:00
|
|
|
xnoremap <Plug>(open-word-under-cursor) <scriptcmd>vim9.Open(getregion(getpos('v'), getpos('.'), { type: mode() })->join())<CR>
|
|
|
|
xmap gx <Plug>(open-word-under-cursor)
|
2025-01-25 16:07:12 +01:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
# vim: ts=8 sts=2 sw=2 et
|