aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-10-31 18:54:53 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-10-31 18:55:08 +0800
commitc1e020b7f3457d3a14e7dda72a4f6ebf06e8f91d (patch)
treec5e847010b83c200a6594fcc94261ddb6e25385e /runtime/doc
parent0a1eeb90cb9a71c0790be2963c8ea054f2b1651b (diff)
downloadrneovim-c1e020b7f3457d3a14e7dda72a4f6ebf06e8f91d.tar.gz
rneovim-c1e020b7f3457d3a14e7dda72a4f6ebf06e8f91d.tar.bz2
rneovim-c1e020b7f3457d3a14e7dda72a4f6ebf06e8f91d.zip
vim-patch:3d7e567: runtime(netrw): simplify gx file handling
It did not work very well, at least on Debian 12, and I am not sure Git Bash and WSL, for example, were taken care of as maintenance stalled. The whole logic was somewhat convoluted with some parts repeatedly invoking failed commands. The file handling was outdated, for example, nowadays Netscape is rarely used, and also opinionated, for example mainly Microsoft Paint and Gimp for Image files. Instead, let's use (xdg-)open and similar commands on other systems which respects the user's preferences. closes: vim/vim#15721 https://github.com/vim/vim/commit/3d7e567ea7392e43a90a6ffb3cd49b71a7b59d1a Co-authored-by: Konfekt <Konfekt@users.noreply.github.com> Co-authored-by: Luca Saccarola <96259932+saccarosium@users.noreply.github.com>
Diffstat (limited to 'runtime/doc')
-rw-r--r--runtime/doc/pi_netrw.txt99
1 files changed, 75 insertions, 24 deletions
diff --git a/runtime/doc/pi_netrw.txt b/runtime/doc/pi_netrw.txt
index 7fc7d4140a..ed95cbb851 100644
--- a/runtime/doc/pi_netrw.txt
+++ b/runtime/doc/pi_netrw.txt
@@ -1465,42 +1465,93 @@ With either form of the command, netrw will first ask for confirmation
that the removal is in fact what you want to do. If netrw doesn't have
permission to remove a file, it will issue an error message.
- *netrw-gx*
+ *netrw-gx* *Open* *Launch*
CUSTOMIZING BROWSING WITH A SPECIAL HANDLER *netrw-x* *netrw-handler* {{{2
Certain files, such as html, gif, jpeg, (word/office) doc, etc, files, are
best seen with a special handler (ie. a tool provided with your computer's
-operating system). Netrw allows one to invoke such special handlers by: >
+operating system). Netrw allows one to invoke such special handlers by:
- * when Exploring, hit the "x" key
- * when editing, hit gx with the cursor atop the special filename
-< (latter not available if the |g:netrw_nogx| variable exists)
+ * hitting gx with the cursor atop the file path or alternatively x
+ in a netrw buffer; the former can be disabled by defining the
+ |g:netrw_nogx| variable
+ * when in command line, typing :Open <path>
-Netrw determines which special handler by the following method:
+One may also use visual mode (see |visual-start|) to select the text that the
+special handler will use. Normally gx checks for a close-by URL or file name
+to pick up the text under the cursor; one may change what |expand()| uses via the
+|g:netrw_gx| variable (options include "<cword>", "<cWORD>"). Note that
+expand("<cfile>") depends on the |'isfname'| setting. Alternatively, one may
+select the text to be used by gx by making a visual selection (see
+|visual-block|) and then pressing gx.
- * if |g:netrw_browsex_viewer| exists, then it will be used to attempt to
- view files. Examples of useful settings (place into your <.vimrc>): >
+The selection function can be adapted for each filetype by adding a function
+Netrw_get_URL_<filetype>, where <filetype> is given by &filetype.
+The function should return the URL or file name to be used by gx, and will
+fall back to the default behavior if it returns an empty string.
+For example, special handlers for links Markdown and HTML are
+>
+" make gx work on concealed links regardless of exact cursor position
+function Netrw_get_URL_markdown()
+ " markdown URL such as [link text](http://ya.ru 'yandex search')
+ try
+ let save_view = winsaveview()
+ if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0
+ return matchstr(getline('.')[col('.')-1:], '\[.\{-}\](\zs' .. g:netrw_regex_url .. '\ze\(\s\+.\{-}\)\?)')
+ endif
+ finally
+ call winrestview(save_view)
+ return ''
+ endtry
+endfunction
+
+function Netrw_get_URL_html()
+ " HTML URL such as <a href='http://www.python.org'>Python is here</a>
+ " <a href="http://www.python.org"/>
+ try
+ let save_view = winsaveview()
+ if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0
+ return matchstr(getline('.')[col('.') - 1 : ],
+ \ 'href=["'.."'"..']\?\zs\S\{-}\ze["'.."'"..']\?/\?>')
+ endif
+ finally
+ call winrestview(save_view)
+ return ''
+ endtry
+endfunction
+<
- :let g:netrw_browsex_viewer= "kfmclient exec"
-< or >
- :let g:netrw_browsex_viewer= "xdg-open"
+Other than a file path, the text under the cursor may be a URL. Netrw uses
+by default the following regular expression to determine if the text under the
+cursor is a URL:
+>
+ g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
<
+
+Netrw determines which special handler by the following method:
+
+ * if |g:netrw_browsex_viewer| exists, then it will be used to attempt to
+ view files. Examples of useful settings (place into your <.vimrc>):
If the viewer you wish to use does not support handling of a remote URL
directory, set |g:netrw_browsex_support_remote| to 0.
- * for Windows 32 or 64, the URL and FileProtocolHandler dlls are used.
- * for Gnome (with gnome-open): gnome-open is used.
- * for KDE (with kfmclient) : kfmclient is used
- * for Mac OS X : open is used.
+ * otherwise:
-The gx mapping extends to all buffers; apply "gx" while atop a word and netrw
-will apply a special handler to it (like "x" works when in a netrw buffer).
-One may also use visual mode (see |visual-start|) to select the text that the
-special handler will use. Normally gx uses expand("<cfile>") to pick up the
-text under the cursor; one may change what |expand()| uses via the
-|g:netrw_gx| variable (options include "<cword>", "<cWORD>"). Note that
-expand("<cfile>") depends on the |'isfname'| setting. Alternatively, one may
-select the text to be used by gx by making a visual selection (see
-|visual-block|) and then pressing gx.
+ * for Windows : explorer.exe is used
+ * for Mac OS X : open is used.
+ * for Linux : xdg-open is used.
+
+To open a file <filepath> by the appropriate handler, type
+
+ :Open <filepath>
+
+No escaping, neither for the shell, nor for Vim's command-line is needed.
+
+To launch a specific application <app> <args>, often <args> being <filepath>,
+
+ :Launch <app> <args>.
+
+Since <args> can be arbitrarily complex, in particular contain many file
+paths, the escaping is left to the user.
Associated setting variables:
|g:netrw_gx| control how gx picks up the text under the cursor