Skip to content

Instantly share code, notes, and snippets.

@tzarskyz
Forked from gfontenot/alfred-vim.applescript
Created February 8, 2014 02:16
Show Gist options
  • Save tzarskyz/8875645 to your computer and use it in GitHub Desktop.
Save tzarskyz/8875645 to your computer and use it in GitHub Desktop.

Installation

  • Can be pasted into the script editor portion of a new Applescript extension for Alfred (Requires the power pack)
  • Should be set as silent and an action without a keyword so you don't pollute Alfred's commands.
  • Pre-built version can be downloaded here

You will need to edit the script and replace e with your vim command

Usage

  1. Select a file in Alfred
  2. Type vim, select the action when you see it
  3. Will launch an iTerm 2 session with the "Vim" profile and automatically start vim for the file, or in the directory you selected.
on alfred_script(q)
set {the_path, file_name} to parse_path(first item of q)
tell application "iTerm"
set _terminal to make new terminal
tell _terminal
launch session "Vim"
tell the last session
write text "cd \"" & the_path & "\""
# Replace e with your vim command
if (file_name is "") then
write text "e"
else
write text "e " & file_name
end if
end tell
end tell
end tell
end alfred_script
on parse_path(input_path)
set posix_path to POSIX file input_path
set the_file to alias posix_path
if (the_file as string) ends with ":" then
return {input_path, ""}
else
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set path_list to text items 1 through -2 of input_path
set file_name to text item -1 of input_path as string
set return_path to path_list as string
set AppleScript's text item delimiters to tid
return {return_path, file_name}
end if
end parse_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment