如何将 NeoVim 设置为我的默认文本/代码编辑器?

DGF*_*DGF 7 macos vim neovim

有没有办法让 NeoVim 作为默认的文本/代码编辑器(没有任何不良的副作用)
相信我,我查看了很多 StackOverflow 问题/答案并尝试了一些方法,但没有任何效果。

注意:我使用的是macOS Big Sur(版本11.2.1)。我想要的是当我点击要在 NeoVim 中打开的文件时。


-->例如,在~/.zshrc中(并添加到 ~/.bash_profile 以防万一)我有

注意:zsh 是我的默认 shell

alias nvim=$HOME/nvim-osx64/bin/nvim
export EDITOR="nvim"
export VISUAL="nvim" 
Run Code Online (Sandbox Code Playgroud)

当我set在终端中执行时,它显示:

EDITOR=nvim
VISUAL=nvim
Run Code Online (Sandbox Code Playgroud)

是的,我退出并启动了终端(我正在使用iTerm2)。我什至重新启动。

--> 我将把我的 $PATH放在这里,以防万一它有任何事情要做。当我这样做时,echo $PATH它显示:

在此输入图像描述


--> 而且,以防万一有人建议:
我不能Select a File>Open With...并选择 NeoVim 作为默认文本编辑器,因为该选项不会显示,而且我也不能这样做,Choose Other因为我无法以这种方式选择 NeoVim。


如果有人需要更多信息,请说出来,我将使用该信息编辑问题。谢谢!

DGF*_*DGF 5

一段时间后,我找到了自己问题的答案,这里是如何将 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/


去看看博客,但你可以这样做:

  1. 启动 Automator(Finder -> 应用程序 -> Automator
  2. 新建文档 -> 选择文档类型:Application
  3. 在“操作”中搜索Run AppleScript并将其拖动到显示“将操作拖动到此处...”之类的位置
  4. 删除AppleScript的默认示例
  5. 将博客中的代码(其中显示 NeoVim.app)复制并粘贴到之前具有默认代码的位置
  6. 保存新的 Automator 应用程序(另存为应用程序格式)。Save it in the Applications folder
  7. 每次单击您希望打开的文件类型时,右键单击它们(例如 .php 文件)。选择Get Info或执行cmd + i,它将打开有关该文件的信息。滚动到显示的位置Open With并选择Other。然后只需转到Aplicattions folder并选择您的新 NeoVim“应用程序”。
  8. 如果您愿意,可以对其他文件类型执行相同的操作。
  9. 现在,您可以双击 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
Run Code Online (Sandbox Code Playgroud)

即使您已经打开了一个窗口,这也会打开一个新窗口。


我对其进行了更改,以便它可以在选项卡中打开:

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
Run Code Online (Sandbox Code Playgroud)

注意:我使用的是 iTerm2。如果您使用的是另一个终端模拟器,请将 iTerm 更改为您的终端名称...