About: Open a web-browser with the URL in the current line   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

I use a similar script when editing html files to view changes made to the file. if exists("loaded_mozilla") finish endif let loaded_mozilla=1 "Setup commands to run mozilla. ":Mozilla - open current file in mozilla. if !exists(':Mozilla') command Mozilla :call s:StartMozilla() endif function! s:StartMozilla() " let s:myfile = getcwd() . "/" . bufname("%") let s:myfile = expand("%:p") let s:a = "mozilla -remote 'openurl(file://"; . s:myfile . ")'" let s:r =system(s:a) "Mozilla is not running so start it." if s:r =~"No running window found." unlet s:a let s:a = "mozilla " . s:myfile . "&" let s:r =system(s:a) endif endfunction

AttributesValues
rdfs:label
  • Open a web-browser with the URL in the current line
rdfs:comment
  • I use a similar script when editing html files to view changes made to the file. if exists("loaded_mozilla") finish endif let loaded_mozilla=1 "Setup commands to run mozilla. ":Mozilla - open current file in mozilla. if !exists(':Mozilla') command Mozilla :call s:StartMozilla() endif function! s:StartMozilla() " let s:myfile = getcwd() . "/" . bufname("%") let s:myfile = expand("%:p") let s:a = "mozilla -remote 'openurl(file://"; . s:myfile . ")'" let s:r =system(s:a) "Mozilla is not running so start it." if s:r =~"No running window found." unlet s:a let s:a = "mozilla " . s:myfile . "&" let s:r =system(s:a) endif endfunction
Version
  • 5(xsd:double)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 305(xsd:integer)
Category
  • Integration
Author
  • Kartik Agaram
Complexity
  • intermediate
Created
  • 2002-08-10(xsd:date)
ID
  • 306(xsd:integer)
NEXT
  • 308(xsd:integer)
Rating
  • 2041(xsd:integer)
abstract
  • I use a similar script when editing html files to view changes made to the file. if exists("loaded_mozilla") finish endif let loaded_mozilla=1 "Setup commands to run mozilla. ":Mozilla - open current file in mozilla. if !exists(':Mozilla') command Mozilla :call s:StartMozilla() endif function! s:StartMozilla() " let s:myfile = getcwd() . "/" . bufname("%") let s:myfile = expand("%:p") let s:a = "mozilla -remote 'openurl(file://"; . s:myfile . ")'" let s:r =system(s:a) "Mozilla is not running so start it." if s:r =~"No running window found." unlet s:a let s:a = "mozilla " . s:myfile . "&" let s:r =system(s:a) endif endfunction Both Netscape and Mozilla accept the remote argument which reloads an open browser with the supplied url. Here is a more generic way to execute a URL (Windows only): vnoremap :let old_reg=@"gvy:silent!!cmd /cstart ":let @"=old_reg If you visually highlight something, then hit CTRL-F5, it will tell Windows to start the default associated application. script#306 - On my machine this will launch Mozilla (since that is my default browser). dave.txt - On my machine this will launch gvim, on default windows machines this would launch notepad.exe. This is my modification. It works for http:, ftp: and file: function! Browser () let line0 = getline (".") let line = matchstr (line0, "http[^ ]*") :if line=="" let line = matchstr (line0, "ftp[^ ]*") :endif :if line=="" let line = matchstr (line0, "file[^ ]*") :endif " echo line exec ":silent !mozilla ".line endfunction map \w :call Browser () Further refinement: (For URL with #?&|%, such as one from a google search) " Evoke a web browser function! Browser () let line0 = getline (".") let line = matchstr (line0, "http[^ ]*") :if line=="" let line = matchstr (line0, "ftp[^ ]*") :endif :if line=="" let line = matchstr (line0, "file[^ ]*") :endif let line = escape (line, "#?&;|%") " echo line exec ":silent !mozilla ".line endfunction map \w :call Browser () Combining a couple previous scripts, here's what I came up with: let $PATH = $PATH . ';c:\Program Files\Mozilla FireFox' "=== evoke a web browser function! Browser () let line0 = getline (".") let line = matchstr (line0, "http[^ ]*") :if line=="" let line = matchstr (line0, "ftp[^ ]*") :endif :if line=="" let line = matchstr (line0, "file[^ ]*") :endif let line = escape (line, "#?&;|%") :if line=="" let line = "\"" . (expand("%:p")) . "\"" :endif exec ':silent !firefox.exe ' . line endfunction map \w :call Browser () ever since i used this command it bothered me that the screen messes up after calling the function. so i decided to use "urlview". well you got to hit enter quit a few times, but you also get all urls presented foud in the current buffer. you can map ":!urlsview %" to something you like A workaround for this behaviour is to add ":redraw!" to the end of the mapping so that it looks like this: map \w :call Browser ():redraw! It will still change the buffer for a moment, though. I modified it so that URL that is passed to firefox is protected by quotes. The changed line is: exec ':silent !firefox.exe ' . "\"" . line . "\"" The complete script now is: let $PATH = $PATH . ';c:\Programs\FireFox1.5' " Evoke a web browser function! Browser () let line0 = getline (".") let line = matchstr (line0, "http[^ ]*") :if line=="" let line = matchstr (line0, "ftp[^ ]*") :endif :if line=="" let line = matchstr (line0, "file[^ ]*") :endif let line = escape (line, "#?&;|%") ":if line=="" " let line = "\"" . (expand("%:p")) . "\"" ":endif exec ':silent !firefox.exe ' . "\"" . line . "\"" endfunction map ,w :call Browser () Under Mac OS X, the open command can handle any URI: function! HandleURI() let s:uri = matchstr(getline("."), '[a-z]*:\/\/[^ >,;:]*') echo s:uri if s:uri != "" exec "!open \"" . s:uri . "\"" else echo "No URI found in line." endif endfunction map w :call HandleURI() OS X version that uses John Gruber's URL regexp and Ruby (as a plugin): ruby << EOF def open_uri re = %r{(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))} line = VIM::Buffer.current.line if url = line[re] system("open", url) VIM::message(url) else VIM::message("No URI found in line.") end end EOF if !exists("*OpenURI") function! OpenURI() :ruby open_uri endfunction endif map w :call OpenURI() Under Linux, this one-liner opens the URL under the cursor: nnoremap w :silent !xdg-open =escape("", "#?&;\|%")
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software