Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tweaked the ranger chooser

  • Loading branch information...
commit 0c63fc654ffc1c20f2d379d4666cd47305440e39 1 parent f9f9207
Federico Marzocchi authored
Showing with 32 additions and 8 deletions.
  1. +32 −8 .vimrc
View
40 .vimrc
@@ -79,14 +79,33 @@ function! WideMsg(msg)
let &ruler=x | let &showcmd=y
endfunction
-function RangerChooser()
- silent !ranger --choosefile=/tmp/chosenfile `[ -z '%:p:h' ] && echo -n . || %:p:h`
- if filereadable('/tmp/chosenfile')
- exec 'edit ' . system('cat /tmp/chosenfile')
- call system('rm /tmp/chosenfile')
- endif
- redraw!
+" Browse with Ranger, starting from given path.
+function! BrowseWithRanger(path)
+ let cmd = "!ranger --choosefile=/tmp/chosenfile --selectfile=" . shellescape(fnamemodify(a:path, ':p'))
+ let basename = fnamemodify(a:path, ':t')
+ if basename[0] == "."
+ let cmd = cmd . " --cmd=" . shellescape('set show_hidden=True')
+ endif
+ silent exe cmd
+
+ if filereadable('/tmp/chosenfile')
+ exec 'edit ' . system('cat /tmp/chosenfile')
+ call system('rm /tmp/chosenfile')
+ endif
+ redraw!
endfunction
+
+" Select a file using the Ranger file manager, either starting from the
+" current dir or the current file.
+function! ChooseFileWithRanger()
+ let cfile = expand('%')
+ if cfile == ""
+ call BrowseWithRanger(getcwd())
+ else
+ call BrowseWithRanger(cfile)
+ endif
+endfunction
+
" }}}
" Settings {{{
@@ -249,7 +268,12 @@ map <leader>t :NERDTreeToggle<CR>
" Cycle windows (splits) with tab in normal mode
nmap <Tab> <C-W>w
-map <leader>o :call RangerChooser()<CR>
+" Choose a file with Ranger, either starting with
+" pwd or the current file (if any) selected.
+map <leader>o :call ChooseFileWithRanger()<CR>
+
+" As above but first selection is fixed on pwd
+map <leader>O :call BrowseWithRanger(getcwd())<CR>
" Toggle fold on dblclick
":map <2-LeftMouse> za
Please sign in to comment.
Something went wrong with that request. Please try again.