Vim Tips Wiki
(Move categories to tip template)
(Change <tt> to <code>, perhaps also minor tweak.)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
{{TipImported
 
{{TipImported
 
|id=628
 
|id=628
|previous=627
+
|previous=626
 
|next=630
 
|next=630
|created=January 1, 2004
+
|created=2004
 
|complexity=basic
 
|complexity=basic
 
|author=Suresh Govindachar
 
|author=Suresh Govindachar
Line 15: Line 15:
 
The following mappings help to execute "things" in win98.
 
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 <tt>\xf</tt> will do it.
+
1) If you are editing a file (eg, html file) file and want to view it, the mapping <code>\xf</code> will do it.
   
2) If you want to execute the string under the cursor (<tt>&lt;cWORD&gt;</tt>):
+
2) If you want to execute the string under the cursor (<code><cWORD></code>):
The mapping <tt>\x</tt> executes the <tt>&lt;cWORD&gt;</tt> "as is", whereas the mapping <tt>\xl</tt> executes it after pre-pending it with the full path to the current file.
+
The mapping <code>\x</code> executes the <code><cWORD></code> "as is", whereas the mapping <code>\xl</code> executes it after pre-pending it with the full path to the current file.
   
Example for <tt>\xf</tt> -- viewing an html file while editing it.
+
Example for <code>\xf</code> -- viewing an html file while editing it.
   
Example for <tt>\x</tt> -- 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
+
Example for <code>\x</code> -- 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.)
 
(It can also be things such as the name of a file (foo.pdf, foo.bat) or directory etc.)
Line 30: Line 30:
   
 
" eXecute File being edited
 
" eXecute File being edited
nmap \xf :silent !start rundll32 url.dll,FileProtocolHandler %:p &lt;CR&gt;
+
nmap \xf :silent !start rundll32 url.dll,FileProtocolHandler %:p <CR>
   
 
"eXecute string below cursor
 
"eXecute string below cursor
nmap \x :silent !start rundll32 url.dll,FileProtocolHandler &lt;cWORD&gt; &lt;CR&gt;
+
nmap \x :silent !start rundll32 url.dll,FileProtocolHandler <cWORD> <CR>
   
 
" eXecute string below cursor after prepending it with path to file
 
" eXecute string below cursor after prepending it with path to file
nmap \xl :silent !start rundll32 url.dll,FileProtocolHandler %:p:h/&lt;cWORD&gt; &lt;CR&gt;
+
nmap \xl :silent !start rundll32 url.dll,FileProtocolHandler %:p:h/<cWORD> <CR>
 
</pre>
 
</pre>
   
Line 50: Line 50:
   
 
<pre>
 
<pre>
nmap \e :silent !start "c:\program files\internet explorer\iexplore.exe" -nohome &lt;cWORD&gt; &lt;CR&gt;
+
nmap \e :silent !start "c:\program files\internet explorer\iexplore.exe" -nohome <cWORD> <CR>
 
</pre>
 
</pre>
   
 
----
 
----
Because sometimes URLs can be within a pair of brackets or &lt;&gt;, I'm using the following mappings:
+
Because sometimes URLs can be within a pair of brackets or <>, I'm using the following mappings:
   
 
<pre>
 
<pre>
nnoremap &lt;silent&gt; &lt;C-L&gt;e
+
nnoremap <silent> <C-L>e
 
\ :exe ':!start cygstart '.
 
\ :exe ':!start cygstart '.
\ matchstr(expand('&lt;cWORD&gt;'),
+
\ matchstr(expand('<cWORD>'),
\ '\%(.\{-}\zs\%(news:\\|mailto:\\|ftp://\\|https\=://\)\)\=[^:;,&lt;&gt;]\+'
+
\ '\%(.\{-}\zs\%(news:\\|mailto:\\|ftp://\\|https\=://\)\)\=[^:;,<>]\+'
\ )&lt;CR&gt;
+
\ )<CR>
   
vnoremap &lt;silent&gt; &lt;C-L&gt;e
+
vnoremap <silent> <C-L>e
\ &lt;C-\&gt;&lt;C-N&gt;:let w:a_save=@a&lt;cr&gt;gv"ay
+
\ <C-\><C-N>:let w:a_save=@a<CR>gv"ay
\ :exe ':!start cygstart '.@a&lt;CR&gt;:let @a=w:a_save&lt;cr&gt;:unlet w:a_save&lt;cr&gt;
+
\ :exe ':!start cygstart '.@a<CR>:let @a=w:a_save<CR>:unlet w:a_save<CR>
 
</pre>
 
</pre>
   

Latest revision as of 07:52, 11 July 2012

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 628 Printable Monobook Previous Next

created 2004 · complexity basic · author Suresh Govindachar · version 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>

References[]

Comments[]

Executing a directory works, but this is not a good usage of the mapping -- since it is better to edit a directory. See :help netrw-explore


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 VimTip394:

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

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:///


See also script#293, which does similar things (not only for Windows).