通过automator实现在finder下自动打开vim

mac可以通过automator自制app, 实现在finder下双击.h, .cpp, .c等等你想用vim编辑的文件,直接打开item的vi窗口编辑该文件

applescript脚本挺好用啊。

本篇转载,原贴地址: http://thepugautomatic.com/2015/02/open-in-iterm-vim-from-finder/


When I double-click a code file in Finder, I want it to open in Vim in a terminal. Not in MacVim. Not in some lesser editor.

There’s plenty of prior work, but nothing worked well for me on OS X 10.10 Yosemite, so I rolled my own.

The end result: double-clicking a file opens a new iTerm window with the file opened in Vim.

Since it execs Vim (replaces the shell process), the window closes when you quit Vim. This also means you can’t ⌃Z out of the Vim session. Think of it as an editor window, not a full-fledged terminal.

1. Get an .app

Download TerminalVim.app, unzip it and stick the app in /Applications.

Or make your own:

  • Open Apple’s “Automator” app.
  • If you get a file dialog, opt to create a “New Document”.
  • Select the “Application” type.
  • Search the action list for “Run AppleScript”, double-click that option.
  • Change the script to this (hat tip to Rob Peck):
on run {input, parameters}
  set myPath to POSIX path of input
  set cmd to "vim " & quote & myPath & quote

  tell application "iTerm"
      activate
      set myTerm to (make new terminal)
      tell myTerm
          set mySession to (make new session at the end of sessions)
          tell mySession to exec command cmd
      end tell
  end tell
end run
  • Save as /Applications/TerminalVim.app.

2. Tell Finder to use your app

  • In Finder, select some file you want to open in Vim, e.g. a .rb file.
  • Hit ⌘I to open the “Get Info” window.
  • Under “Open with:”, choose “TerminalVim.app”. You may need to select “Other…” and then browse.
  • Hit the “Change All…” button and confirm.

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

3. Profit

That’s it!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值