aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/xolox/misc/open.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/xolox/misc/open.vim')
-rw-r--r--autoload/xolox/misc/open.vim32
1 files changed, 27 insertions, 5 deletions
diff --git a/autoload/xolox/misc/open.vim b/autoload/xolox/misc/open.vim
index 1fb24e0..b369f4f 100644
--- a/autoload/xolox/misc/open.vim
+++ b/autoload/xolox/misc/open.vim
@@ -1,6 +1,7 @@
-" Vim auto-load script
+" Integration between Vim and its environment.
+"
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: November 21, 2011
+" Last Change: May 19, 2013
" URL: http://peterodding.com/code/vim/misc/
if !exists('s:version')
@@ -9,7 +10,20 @@ if !exists('s:version')
let s:handlers = ['gnome-open', 'kde-open', 'exo-open', 'xdg-open']
endif
-function! xolox#misc#open#file(path, ...)
+function! xolox#misc#open#file(path, ...) " {{{1
+ " Given a pathname as the first argument, this opens the file with the
+ " program associated with the file type. So for example a text file might
+ " open in Vim, an `*.html` file would probably open in your web browser and
+ " a media file would open in a media player.
+ "
+ " This should work on Windows, Mac OS X and most Linux distributions. If
+ " this fails to find a file association, you can pass one or more external
+ " commands to try as additional arguments. For example:
+ "
+ " :call xolox#misc#open#file('/path/to/my/file', 'firefox', 'google-chrome')
+ "
+ " This generally shouldn't be necessary but it might come in handy now and
+ " then.
if xolox#misc#os#is_win()
try
call xolox#shell#open_with_windows_shell(a:path)
@@ -35,7 +49,15 @@ function! xolox#misc#open#file(path, ...)
throw printf(s:enoimpl, s:script, 'xolox#misc#open#file')
endfunction
-function! xolox#misc#open#url(url)
+function! xolox#misc#open#url(url) " {{{1
+ " Given a URL as the first argument, this opens the URL in your preferred or
+ " best available web browser:
+ "
+ " - In GUI environments a graphical web browser will open (or a new tab will
+ " be created in an existing window)
+ " - In console Vim without a GUI environment, when you have any of `lynx`,
+ " `links` or `w3m` installed it will launch a command line web browser in
+ " front of Vim (temporarily suspending Vim)
let url = a:url
if url !~ '^\w\+://'
if url !~ '@'
@@ -56,7 +78,7 @@ function! xolox#misc#open#url(url)
call xolox#misc#open#file(url, 'firefox', 'google-chrome')
endfunction
-function! s:handle_error(cmd, output)
+function! s:handle_error(cmd, output) " {{{1
if v:shell_error
let message = "open.vim %s: Failed to execute program! (command line: %s%s)"
let output = strtrans(xolox#misc#str#trim(a:output))