sponsor Vim development Vim logo Vim Book Ad

basic Tip #628: Execut "things" in Win98 from within VIM

 tip karma   Rating 4/3, Viewed by 1044 

created:   January 1, 2004 16:07      complexity:   basic
author:   Suresh Govindachar      as of Vim:   6.0

      
The following mappings help to execute "things" in win98.

1) If you are editing a file (eg, html file) file and want
   to view it, the mapping \xf will do it.

2) If you want to execute the string under the cursor (<cWORD>):  

        The mapping \x executes the <cWORD> "as is", whereas
        the mapping \xl executes it after pre-pending it with the
        full path to the current file.

Example for \xf -- viewing an html file while editing it.

Example for \x -- the string under the cursor can be a google
search for the word mail on this web-site:

http://www.google.com/search?q=mail+site:vim.sourceforge.net

(It can also be things such as the name of a file (foo.pdf,
foo.bat) or directory etc.)

"__________________________________________
"The mappings:

" eXecute File being edited
nmap \xf  :silent !start rundll32 url.dll,FileProtocolHandler %:p <CR>        

"eXecute string below cursor
nmap \x   :silent !start rundll32 url.dll,FileProtocolHandler <cWORD> <CR>        

" eXecute string below cursor after prepending it with path to file
nmap \xl  :silent !start rundll32 url.dll,FileProtocolHandler %:p:h/<cWORD> <CR>        

"__________________________________________
See:
  help  filename-modifiers
  help  <cWORD>
  

 rate this tip  Life Changing Helpful Unfulfilling 

<<Customizing ftplugin, syntax etc. (eg for TeX) | After quitting VIM, comeback to the same file position where you were while quitting. >>

Additional Notes

Suresh Govindachar, January 1, 2004 16:27
Executing a directory works, but this is not a good usage
of the mapping -- since it is better to edit a directory!
See help file-explorer
Suresh Govindachar, January 1, 2004 20:08
Although the example given above about searching this web-site
for "mail" does work with \x, there is a bug in rundll32 that
prevents \x from working on url's that end with an actual file -- see

"http://support.microsoft.com/default.aspx?scid=kb;en-us;283225";

The following mapping can be used for such cases (based on vimtip #394):

  nmap \e   :silent !start "c:\program files\internet explorer\iexplore.exe" -nohome <cWORD> <CR>    

hermitte {at} free {dot} fr, January 6, 2004 1:51
Because sometimes URLs can be within a pair of brackets or <>, I'm using : the following mappings:

nnoremap <silent> <C-L>e
      \ :exe ':!start cygstart '.
      \    matchstr(expand('<cWORD>'),
      \    '\%(.\{-}\zs\%(news:\\|mailto:\\|ftp://\\|https\=://\)\)\=[^:;,<>]\+'
      \ )<CR>

vnoremap <silent> <C-L>e
      \ <C-\><C-N>:let w:a_save=@a<cr>gv"ay
      \ :exe ':!start cygstart '.@a<CR>:let @a=w:a_save<cr>:unlet w:a_save<cr>

(Note as filenames may contains spaces, I haven't tried to support file:///)
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo