Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use the NerdTree plugin for MacVim religiously, and find myself often wanting to open a folder in the Finder to work with the files. An example would be wanting to preview and copy some images.

Is there a quick way to do this that doesn't involve changing the current directory? My perfect scenario would be:

  • Move cursor to desired folder
  • Press "some key"
  • Folder opens up in the finder.
share|improve this question

2 Answers 2

Try the following

Add this map to your vimrc

nmap <Leader>b :NERDTreeFind<CR>

This you can do the following from an open file

  1. < Leader >b => highlight the file in NerdTree
  2. m => display the file options
  3. r => reveal in Finder

The above assumes you're running a GUI like MacVim for example. If you're in the shell you can add this to your vimrc

function! s:RevealInFinder()
  if filereadable(expand("%"))
    let l:command = "open -R %"
  elseif getftype(expand("%:p:h")) == "dir"
    let l:command = "open %:p:h"
  else
    let l:command = "open ."
  endif
  execute ":silent! !" . l:command
 " For terminal Vim not to look messed up.
 redraw!
endfunction command! Reveal call <SID>RevealInFinder()

then when you're in the file you want to reveal in finder you do

:Reveal
share|improve this answer

The shell command to open a folder is

$ open /path/to/folder

In a Vim function, this command could be invoked like this:

let g:mypath = /path/to/folder
execute "silent !open " . g:mypath

NERDTree's documentation has a simple and easy to follow example that you can expand using the global objects listed above.

share|improve this answer
    
Pretty sure your links to the documentation are out of date. –  Ben Mar 24 at 19:23
    
@Ben, that kind of thing could happen, yes. Links fixed. –  romainl Mar 24 at 20:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.