【问题标题】:How do I make NeoVim my default text/code editor?如何让 NeoVim 成为我的默认文本/代码编辑器?
【发布时间】:2021-11-13 01:46:41
【问题描述】:

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

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


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

注意:zsh 是我的默认shell

alias nvim=$HOME/nvim-osx64/bin/nvim
export EDITOR="nvim"
export VISUAL="nvim" 

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

EDITOR=nvim
VISUAL=nvim

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

--> 我会把 my $PATH 放在这里,以防万一它有什么需要做的。当我执行echo $PATH 时,它显示:


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


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

【问题讨论】:

标签: macos vim neovim


【解决方案1】:

在终端中设置变量不会影响 GUI 文件关联。为此,您必须更改操作系统的文件关联。

虽然它看起来是一个小项目并且不受支持,但我在使用 duti 时获得了很好的体验。它是 Apple 文件扩展 API 的包装器。配置确实花了我一分钟才弄清楚。如果我能找到它,我会发布它。

【讨论】:

    【解决方案2】:

    过了一会儿,我找到了自己问题的答案,这里是如何在 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(查找器 -> 应用程序 -> Automator
    2. 新建文档 -> 为您的文档选择一种类型:Application
    3. 在“操作”中搜索 Run AppleScript 并将其拖到显示“将操作拖到此处...”之类的位置
    4. 删除AppleScript的默认示例
    5. 将博客中的代码(显示为 NeoVim.app)复制并粘贴到之前的默认代码位置
    6. 保存新的 Automator 应用程序(另存为应用格式)。 Save it in the Applications folder
    7. 右键单击您希望在每次单击时打开的文件类型(例如 .php 文件)。选择Get Infocmd + i,它将打开有关该文件的信息。滚动到显示Open With 的位置并选择Other。然后只需转到Aplicattions folder 并选择您的新 NeoVim“应用程序”。
    8. 如果您愿意,对其他文件类型执行相同操作。
    9. 您现在可以双击您的 PHP 文件(或其他如果您这样做的话)并在 NeoVim 中打开它们。尽情享受吧!

    注意:您确实需要执行Right-ClickGet 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 的位置更改为您的终端名称...

    【讨论】:

      【解决方案3】:

      对于在 MacOS 上使用 Kitty 的任何人,我找到了一种使用远程控制功能完成此任务的非常简单的方法。

      首先,您需要在kitty.conf 中设置以下内容:

      allow_remote_control yes
      listen_on unix:/tmp/mykitty
      

      在@DGF 的回答中使用 Automator,我创建了一个具有“运行 Shell 脚本”操作的应用程序,这就是脚本:

      if [ -z "$(pgrep kitty)" ]
      then
          open /Applications/kitty.app
          sleep 3 # allow ample time to startup and start listening
      fi
      
      /usr/local/bin/kitty @ --to=unix:/tmp/mykitty-$(pgrep kitty) launch --type=os-window nvim "$@"
      

      将其保存为应用程序,然后从“打开方式”中选择它!

      注意:老实说,如果 kitty 尚未运行,则处理启动它的逻辑有点不稳定。但是当小猫已经在运行时,它似乎工作得很好,当然这对我来说大部分时间都是如此。此外,如果 kitty 正在运行但没有窗口,它根本不起作用。 :\

      【讨论】:

        猜你喜欢
        • 2017-05-14
        • 2020-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-18
        • 2021-03-05
        • 2012-08-03
        相关资源
        最近更新 更多