Vim Tips 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)