Last active
July 15, 2023 00:15
-
-
Save cytopia/4438ea971833b519abb2 to your computer and use it in GitHub Desktop.
Ranger as file explorer in vim
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
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