有馬総一郎のブログ

(彼氏の事情)

2020年05月24日 23:50:39 JST - 1 minute read - Comments - Vim

WindowsでVimからExcelを開く(おまけで特定のURLを既定ブラウザで開く)

コマンドプロンプトから普通にやるとexcelでは起動できず、start excelでないと起動できない…Why?

だから:!start excel ファイル.xlsxするとE371: コマンドがありませんとエラー表示されてしまう。

!cmd /c start excel ファイル.xlsxとするば起動できるけど長すぎる…

let $PATH .= ';C:\Program Files (x86)\Microsoft Office\Office16'
command! -nargs=* Excel call s:LaunchExcel(<f-args>)
function! s:LaunchExcel (file)
  let file = '"' . a:file . '"'
  let command = '!Excel ' . file
  execute command
endfunction
command! -nargs=* Word call s:LaunchWord(<f-args>)
function! s:LaunchWord (file)
  let file = '"' . a:file . '"'
  let command = '!WINWORD ' . file
  execute command
endfunction
command! -nargs=* POWERPNT call s:LaunchPOWERPNT(<f-args>)
function! s:LaunchPOWERPNT (file)
  let file = '"' . a:file . '"'
  let command = '!POWERPNT ' . file
  execute command
endfunction

とか考えたのだけど…コマンドプロンプトが立ち上がるのがウザい…

で調べると、どうも vimstartというコマンドがあって、 Vimからアプリケーションをバックグラウンドで起動するいくつかの方法 - Humanityな情報を発見する。

なので!start ファイル.xlsxとすれば既定のアプリで開くことが出来る…上のようなファンクション要らない。知らなかった

あと、!start excelで新規Excelを起動をすることは出来る。引数付けると上記のように駄目だけど。

Excelだけでなく、特定のurlをブラウザを開くときも!start 特定のURLでよろしくやってくれる。

Tags: Windows Vim

simplenote.vimでパスワードが合っているのにログインが失敗する SQL Server XML型メソッド value()の使い方

comments powered by Disqus