Skip to content

Instantly share code, notes, and snippets.

@napcs
Last active February 24, 2025 14:19
Show Gist options
  • Save napcs/2d8376e941133ccfad63e33bf1b1b60c to your computer and use it in GitHub Desktop.
Save napcs/2d8376e941133ccfad63e33bf1b1b60c to your computer and use it in GitHub Desktop.
Open file in Terminal Vim on OSX
  1. Open Automator
  2. Choose "New Document"
  3. Locate "Run AppleScript" and double-click it
  4. Paste the Applescript code into the box
  5. Save as /Applications/TerminalVim.app
  6. In Finder, select some file you want to open in Vim, e.g. a .rb file.
  7. Hit ⌘I to open the “Get Info” window.
  8. Under “Open with:”, choose TerminalVim.app. You may need to select “Other…” and then browse.
  9. Hit the “Change All…” button and confirm.

Now all .rb files in Finder will open in Vim.

on run {input, parameters}
set filename to quoted form of POSIX path of input
set cmd to "clear;cd `dirname " & filename & "`;vim " & filename
tell application "iTerm"
tell the current window
create tab with default profile
tell the current session
write text cmd
end tell
end tell
end tell
end run
@Spirarel
Copy link

Tried the last version. Often there is an error:

You'll need to create a new window if one isn't there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment