After a while I found the answer to my own question, here it is how you can set NeoVim in Mac as the default text editor. Now, you will be able click on files and opening them in NeoVim:
Some people recommended me to have a look at the follow links:
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
That didn't work for me but it served as a reference to look up related topics (automator + neovim).
After a while, I discover this blog:
https://blog.schembri.me/post/neovim-everywhere-on-macos/
Go and have a look at the blog, but here it is how you do it:
- Launch Automator (Finder -> Applications ->
Automator
)
- New Document -> Choose a type for your document:
Application
- In Actions search for
Run AppleScript
and drag that to where it says something like "Drag actions here..."
- Delete the default example of AppleScript
- Copy and Paste the code in the blog (where it says NeoVim.app) to where it previous had the default code
- Save the new Automator app (save as aplicattion format).
Save it in the Applications folder
- Right-Click a file type you wish to open every time you click on them (e.g. .php file). Select
Get Info
or do cmd + i
, it will open informations about that file. Scroll to wher it says Open With
and select Other
. Then just go to Aplicattions folder
and select your new NeoVim "app".
- Do the same to other file types if you wish.
- You can now double click on your PHP files (or others if you did the same) and open them in NeoVim. Enjoy!
Note: You really need to do Right-Click
, Get Info
and look for Open With
to change in all files with that extension. If you skip Get Info
and just Right-Click + Open With, it will only work for that specific file...
This is the code from the blog:
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
This would open a new window even if you already had one open.
I change it so that it would open in a tab:
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
Note: I'm using iTerm2. If you are using another Terminal Emulator, change where it says iTerm to the name of your terminal...