Skip to content

Instantly share code, notes, and snippets.

@ashearer
Created December 17, 2010 23:38
Show Gist options
  • Save ashearer/745908 to your computer and use it in GitHub Desktop.
Save ashearer/745908 to your computer and use it in GitHub Desktop.
Vim key bindings for Mac to open a Terminal or Finder window pointed at the current file's parent
" Add to ~/.vimrc
" F5 opens a Terminal window with its current directory set to the current
" file's parent.
" [The command uses an extra CR at the end to get rid of the "Continue"
" prompt, since it will always run over a one-line status bar. :silent doesn't
" help when the command itself is too long for the status bar. Putting the
" command into a variable before executing may be another way to do it.
" Even better: in a function, save sc (showcmd), set nosc, run cmd, restore sc.]
map <F5> :!osascript -e 'tell app "Terminal" to activate do script with command "cd " & quoted form of "%:p:h"'<CR><CR>
" Shift-F5 opens current buffer's folder in Finder, selecting the current file
" if it exists. Works for both directories and files.
map <S-F5> :silent execute '![ -f "%:p" ] && open -R "%:p" \|\| open "%:p:h"'<CR>
@ashearer
Copy link
Author

Place in .vimrc. Works with both MacVim and built-in vim on Mac OS X.

Hit F5 to open a new Terminal window with the current directory set to the parent of the current file.

Hit Shift-F5 to open a Finder window with the current file or folder selected.

Spaces and Unicode characters are OK in file paths, but quotes and backslashes generally aren't.

@meddulla
Copy link

Thanks :) Was just looking for this!

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