Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,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 whoever posted them. This site is not responsible for what they say.
Use Terminal's vi as default text editor
Authored by: ctuft on Mar 18, '08 08:42:22PM
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 Mar 20, '08 10:42:35PM

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 May 21, '09 06:44:36AM

Awesome tip, Chris! One of the best on this site!



[ Reply to This | # ]