Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!


Click here to return to the 'Use Terminal's vi as default text editor' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Use Terminal's vi as default text editor
Authored by: ctuft on Tue, Mar 18 2008 at 8:42PM PDT
I tend to use iTerm instead of Terminal, so I modified the script a bit so it works in iTerm. This will also deal with multiple files (opens a new tab for each), and it will also leave you in the same directory where the opened text file resides:
on run
	set this_inputfile to ""
	set this_inputfiledir to "~/Desktop"
	my launchVI(this_inputfile, this_inputfiledir)
end run

on open inputfiles
	repeat with this_inputfile in inputfiles
		tell application "Finder"
			set this_inputfiledir to quoted form of POSIX path of (container of this_inputfile as string)
		end tell
		my launchVI(this_inputfile, this_inputfiledir)
	end repeat
end open

on launchVI(this_inputfile, this_inputfiledir)
	tell application "iTerm"
		activate
		tell the first terminal
			set mySession to (make new session at the end of sessions)
			tell mySession
				set short_name to system attribute "USER"
				exec command "login -fp " & short_name
				if this_inputfile ≠ "" then
					write text "cd " & this_inputfiledir
					write text "vi " & quoted form of POSIX path of this_inputfile & return
				else
					write text "cd " & this_inputfiledir
					write text "vi"
				end if
			end tell
		end tell
	end tell
end launchVI
-Chris

[ Reply to This | # ]
Use Terminal's vi as default text editor
Authored by: sominsky on Thu, Mar 20 2008 at 10:42PM PDT
Ooh, this is nice. I'm thrilled that my first hint submission has gone so well. Maybe I'll do more :)

I'm saving your script in place of my own, by the way. This does *exactly* what I want.

[ Reply to This | # ]
Use Terminal's vi as default text editor
Authored by: Paul Burney on Thu, May 21 2009 at 6:44AM PDT
Awesome tip, Chris! One of the best on this site!

[ Reply to This | # ]