Skip to content

Instantly share code, notes, and snippets.

@cytopia
Last active July 15, 2023 00:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cytopia/4438ea971833b519abb2 to your computer and use it in GitHub Desktop.
Save cytopia/4438ea971833b519abb2 to your computer and use it in GitHub Desktop.
Ranger as file explorer in vim
function RangerExplorer()
exec "silent !ranger --choosefile=/tmp/vim_ranger_current_file " . expand("%:p:h")
if filereadable('/tmp/vim_ranger_current_file')
exec 'edit ' . system('cat /tmp/vim_ranger_current_file')
call system('rm /tmp/vim_ranger_current_file')
endif
redraw!
endfun
map <Leader>x :call RangerExplorer()<CR>
" Explanation:
" * ranger --choosefile lets ranger act as a file choose (quit ranger on open file)
" * When the file can be read, edit its contents in vim
" * Afterwards delete the temporary file and refresh the screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment