vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

openPlugin.vim (1442B)


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