Mac OS X:双击文件时如何在终端中打开vim

six*_*ude 21 mac vim macos

我已经定义了我自己的自定义 vim 文件类型,并带有突出显示等功能。当我双击它时,我想使用基于终端的 vim 打开它。我正在使用 mac os x。关于如何开始的任何指示?

gho*_*ppe 19

创建一个 Automator 应用程序来运行以下 applescript:

on run {input}
   set the_path to POSIX path of input
   set cmd to "vim " & quoted form of the_path
   tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
   tell application "Terminal"
      activate
      if terminalIsRunning is true then
         do script with command cmd
      else
         do script with command cmd in window 1
      end if
   end tell
end run
Run Code Online (Sandbox Code Playgroud)

保存自动机应用程序。(例如,将其命名为Vim Launcher

右键单击(或按住 Control 单击)您的自定义 vim 类型文件(例如,使用.vim作为扩展名),然后在打开方式...选择底部选项Other...并找到您的 Automator 应用程序(例如Vim Launcher),双击点击它。

繁荣。

  • 要在 Automator 中创建,您可以单击“新建文档”,选择“应用程序”模板。在`Actions->Library` 选项卡中,点击`Utilities`,然后点击`Run AppleScript`。 (4认同)