Created
October 29, 2012 06:07
-
-
Save tacahiroy/3971853 to your computer and use it in GitHub Desktop.
Vim: open the current file's location using file manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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