Vim Tips Wiki

Finding phone numbers

Revision as of 05:53, July 13, 2012 by JohnBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
1,614pages on
this wiki
Tip 872 Printable Monobook Previous Next

created 2005 · complexity intermediate · author Bertram Scharpf · version 6.0

When editing a file containing phone numbers, the following can be used to dial the number under the cursor. It uses a shell script (not shown) to make a modem dial the number.

" Return phone number under cursor.
" If no number, return an empty string (if argument is zero),
" otherwise throw an error to abort script.
function! CPhone(check)
  let s = '[-+./()0-9 ]*'
  let nr = matchstr(getline('.'), '\s*\zs'.s.'\%'.col('.').'c'.s)
  let nr = substitute(nr, '\s\+$', '', '')
  if a:check && empty(nr)
    throw 'No phone number under cursor.'
  return nr

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

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

After sourcing the above script:

  • In any file, put the cursor on a phone number and type @p to dial the number.
  • In any file with a name starting with "phone", put the cursor on a phone number and press Enter to dial the number.

The shell script dial (not shown) uses its argument to write modem control sequences to /dev/ttysS0 to cause the modem to dial the phone number. The script removes all non-digit characters from the number, then does something like this shell command:

echo -ne 'atdt,<number>;h0\r' >/dev/ttyS0


Not many people will have a modem (or the required dial script) to try this tip, but there are some useful ideas that might be useful for other applications. JohnBeckett 10:54, May 11, 2012 (UTC)

Around Wikia's network

Random Wiki