LoginSignup
3
3

More than 3 years have passed since last update.

Macでnvim(neovim)をFinderの「このアプリケーションから開く」や右クリックメニューで開けるようにする(iTerm経由)

Last updated at Posted at 2020-01-26

概要

Macにて、nvim(neovim)を導入しただけでは、Finderの「このアプリケーションから開く」で利用できません。これを解決する手順を記載しています。

前提条件

  • neovimがインストール済みであること(本例ではHomeBrewでインストールしている)
  • iTermがインストールされていること

手順

  • 「Automater」を開きます。
  • 書類の種類から、「アプリケーション」を開きます。
  • 検索欄から、「実行」で検索し、「AppleScriptを実行」をダブルクリック。(右側の画面に表示されます。)
  • コードを下記のコードで上書きします。
on run {input, parameters}

    # seem to need the full path at least in some cases
    # -p opens files in separate tabs
    set nvimCommand to "/usr/local/bin/nvim -p "

    set filepaths to ""
    if input is not {} then
        repeat with currentFile in input
            set filepaths to filepaths & quoted form of POSIX path of currentFile & " "
        end repeat
    end if

    if application "iTerm" is running then
        tell application "iTerm"
            create window with default profile command nvimCommand & filepaths
        end tell
    else
        tell application "iTerm"
            tell current session of current window
                write text nvimCommand & filepaths
            end tell
        end tell
    end if
end run
  • 名前を付けて保存します。
  • 保存したファイルを「アプリケーション」フォルダへ移動します。

以上で、保存したものがFinderの「このアプリケーションから開く(その他)」から選択できるようになり、iTerm経由のneovimから開くことができます。

ついでに、「右クリックメニュー」にneovimから開くを追加

  • 「Automater」を開きます。
  • 書類の種類から、「クイックアクション」を開きます。
  • 「ワークフローが受け取る現在の項目」で、「ファイルまたはフォルダ」を選択する。
  • 左側のメニューから「Finder項目を開く」をダブルクリック。(右側の画面に表示されます。)
  • 「このアプリケーションで開く」で、上述の手順で作成したアプリケーションを選択します。
  • 名前を付けて保存します。名前は「右クリックメニューに表示したい文字」にします。

以上で、Finderでファイルを選択した際の右クリックメニューからneovimが開けるようになります。

補足事項

iTermから開けるようにしたのは、macのTerminal.appがTrue Colorに非対応の為、True Colorを前提としたカラーテーマ(Color Scheme)が正しく表示されない為でした。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3