Skip to content

Instantly share code, notes, and snippets.

@tacahiroy
Created October 29, 2012 06:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacahiroy/3971853 to your computer and use it in GitHub Desktop.
Save tacahiroy/3971853 to your computer and use it in GitHub Desktop.
Vim: open the current file's location using file manager
" open the current editing file's location using file manager
function! s:open_with_filer()
let cmd = s:get_command()
let path = s:convert_path(expand('%:p:h'))
if cmd is# ''
call g:echohl('Error', 'Your system is not supported.')
return
endif
execute printf('!%s %s', cmd, path)
endfunction
nnoremap <Leader>e :<C-u>call <SID>open_with_filer()<Cr>
function! s:convert_path(path)
if has('win32') || has('win64')
return '"' . substitute(a:path, '/', '\', 'g') . '"'
else
return a:path
endif
endfunction
function! s:get_command()
if has ('mac')
return 'open -a Finder'
elseif has('unix') && has('gui_gnome')
return 'nautilus'
elseif has('win32') || has('win64')
return 'start explorer'
else
return ''
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment