Vim Tips Wiki
m (Fixed formatting)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=872
 
|id=872
  +
|previous=871
|title=Finding phone numbers
 
  +
|next=873
|created=February 10, 2005 2:14
+
|created=February 10, 2005
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Bertram Scharpf
 
|author=Bertram Scharpf
 
|version=6.0
 
|version=6.0
 
|rating=3/6
 
|rating=3/6
 
}}
|text=
 
I have a little script making the my modem dial phone numbers. As the numbers are contained in a file I edit with Vim, I call the script by
+
I have a little script making my modem dial phone numbers. As the numbers are contained in a file I edit with Vim, I call the script with:
   
 
<pre>
 
<pre>
func CPhone( ...)
+
func CPhone( ...)
" Get phone number under cursor
+
" Get phone number under cursor
let s="[-+./()0-9 ]*"
+
let s="[-+./()0-9 ]*"
let nr=matchstr( getline("."), "\\s*\\zs".s."\\%".col(".")."c".s)
+
let nr=matchstr( getline("."), "\\s*\\zs".s."\\%".col(".")."c".s)
let nr=substitute( nr, "\\s\\+$", "", "")
+
let nr=substitute( nr, "\\s\\+$", "", "")
if nr == "" &amp;&amp; a:0 &amp;&amp; a:1
+
if nr == "" &amp;&amp; a:0 &amp;&amp; a:1
throw "No phone number under cursor."
+
throw "No phone number under cursor."
  +
endif
endif
 
return nr
+
return nr
endf
+
endf
   
 
let @p=":exec \":!dial '\".CPhone(1).\"'\"\&lt;cr&gt;"
   
 
augroup LocalUser
let @p=":exec \":!dial '\".CPhone(1).\"'\"\&lt;cr&gt;"
 
 
autocmd BufRead phone* nnoremap &lt;buffer&gt; &lt;cr&gt; :exec ":!dial '".CPhone(1)."'"&lt;cr&gt;
 
 
augroup END
 
augroup LocalUser
 
autocmd BufRead phone* nnoremap &lt;buffer&gt; &lt;cr&gt; :exec ":!dial '".CPhone(1)."'"&lt;cr&gt;
 
augroup END
 
 
</pre>
 
</pre>
}}
 
   
== Comments ==
+
==Comments==
This makes no sense? Does vim dial the number?
+
This makes no sense? Does Vim dial the number?
   
Mohanjit Singh Malik
 
, February 15, 2005 15:13
 
 
----
 
----
My shell script `dial' does that. I omitted it because writing "ATDT" sequences to `/dev/ttysS0' has nothing to do with Vim.
+
My shell script 'dial' does that. I omitted it because writing "ATDT" sequences to '/dev/ttysS0' has nothing to do with Vim.
 
Roughly spoken, the script does an ":!echo -ne 'atdt,&lt;number&gt;;h0\r' &gt;/dev/ttyS0", having stripped off all non-digit characters before.
 
   
 
Roughly spoken, the script does an ":!echo -ne 'atdt,&lt;number&gt;;h0\r' &gt;/dev/ttyS0", having stripped off all non-digit characters before.
   
Bertram Scharpf
 
, February 16, 2005 1:32
 
 
----
 
----
<!-- parsed by vimtips.py in 0.448448 seconds-->
 

Revision as of 10:05, 1 December 2007

Tip 872 Printable Monobook Previous Next

created February 10, 2005 · complexity intermediate · author Bertram Scharpf · version 6.0


I have a little script making my modem dial phone numbers. As the numbers are contained in a file I edit with Vim, I call the script with:

func CPhone( ...)
  " Get phone number under cursor
  let s="[-+./()0-9 ]*"
  let nr=matchstr( getline("."), "\\s*\\zs".s."\\%".col(".")."c".s)
  let nr=substitute( nr, "\\s\\+$", "", "")
  if nr == "" && a:0 && a:1
    throw "No phone number under cursor."
  endif
  return nr
endf

let @p=":exec \":!dial '\".CPhone(1).\"'\"\<cr>"

augroup LocalUser
  autocmd BufRead phone* nnoremap <buffer> <cr> :exec ":!dial '".CPhone(1)."'"<cr>
augroup END

Comments

This makes no sense? Does Vim dial the number?


My shell script 'dial' does that. I omitted it because writing "ATDT" sequences to '/dev/ttysS0' has nothing to do with Vim.

Roughly spoken, the script does an ":!echo -ne 'atdt,<number>;h0\r' >/dev/ttyS0", having stripped off all non-digit characters before.