过了一会儿,我找到了自己问题的答案,这里是如何在 Mac 中将 NeoVim 设置为默认文本编辑器。现在,您将能够单击文件并在 NeoVim 中打开它们:
有人推荐我看看以下链接:
https://gist.github.com/Huluk/5117702
https://superuser.com/questions/139352/mac-os-x-how-to-open-vim-in-terminal-when-double-click-on-a-file
这对我不起作用,但它可以作为查找相关主题的参考(automator + neovim)。
过了一会儿,我发现了这个博客:
https://blog.schembri.me/post/neovim-everywhere-on-macos/
去看看博客,但是这里是你如何做到的:
- 启动 Automator(查找器 -> 应用程序 ->
Automator)
- 新建文档 -> 为您的文档选择一种类型:
Application
- 在“操作”中搜索
Run AppleScript 并将其拖到显示“将操作拖到此处...”之类的位置
- 删除AppleScript的默认示例
- 将博客中的代码(显示为 NeoVim.app)复制并粘贴到之前的默认代码位置
- 保存新的 Automator 应用程序(另存为应用格式)。
Save it in the Applications folder
- 右键单击您希望在每次单击时打开的文件类型(例如 .php 文件)。选择
Get Info 或cmd + i,它将打开有关该文件的信息。滚动到显示Open With 的位置并选择Other。然后只需转到Aplicattions folder 并选择您的新 NeoVim“应用程序”。
- 如果您愿意,对其他文件类型执行相同操作。
- 您现在可以双击您的 PHP 文件(或其他如果您这样做的话)并在 NeoVim 中打开它们。尽情享受吧!
注意:您确实需要执行Right-Click、Get Info 并查找Open With 以更改所有具有该扩展名的文件。如果您跳过 Get Info 并仅右键单击 + 打开方式,它将仅适用于该特定文件...
这是来自博客的代码:
on run {input, parameters}
set cmd to "nvim"
if input is not {} then
set filePath to POSIX path of input
set cmd to "nvim \"" & filePath & "\""
end if
tell application "iTerm"
create window with default profile
tell the current window
tell the current session to write text cmd
end tell
end tell
end run
即使您已经打开了一个新窗口,这也会打开一个新窗口。
我将其更改为在选项卡中打开:
on run {input, parameters}
set cmd to "nvim"
if input is not {} then
set filePath to POSIX path of input
set cmd to "nvim \"" & filePath & "\""
end if
tell application "iTerm"
tell the current window
create tab with default profile
tell the current session to write text cmd
end tell
end tell
end run
注意:我使用的是 iTerm2。如果您使用的是另一个终端仿真器,请将 iTerm 的位置更改为您的终端名称...