diff options
author | Israel Chauca Fuentes <israelvarios@fastmail.fm> | 2013-09-17 23:51:43 -0400 |
---|---|---|
committer | Israel Chauca Fuentes <israelvarios@fastmail.fm> | 2013-09-17 23:51:43 -0400 |
commit | ee35f41d6b41dbf71cb558ecd8c69883738ff98a (patch) | |
tree | 35a7916078a9c73c2e3386c0fcdb7a54d8eadbd6 /doc/examples | |
parent | 75533afccc5e96b231565adba923ba373cba2c6f (diff) | |
download | ranger-ee35f41d6b41dbf71cb558ecd8c69883738ff98a.tar.gz |
Update vim_file_chooser.vim
Allow choosing multiple files. Add ex command :RangerChooser. Use the value of mapleader for the keybinding.
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/vim_file_chooser.vim | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/doc/examples/vim_file_chooser.vim b/doc/examples/vim_file_chooser.vim index 4f5fa3f2..064fbab6 100644 --- a/doc/examples/vim_file_chooser.vim +++ b/doc/examples/vim_file_chooser.vim @@ -2,16 +2,32 @@ " " Add ranger as a file chooser in vim " -" If you add this function and the key binding to the .vimrc, ranger can be -" started using the keybinding ",r". Once you select a file by pressing -" enter, ranger will quit again and vim will open the selected file. +" If you add this code to the .vimrc, ranger can be started using the command +" ":RagerChooser" or the keybinding "<leader>r". Once you select one or more +" files, press enter and ranger will quit again and vim will open the selected +" files. -fun! RangerChooser() - exec "silent !ranger --choosefile=/tmp/chosenfile " . expand("%:p:h") - if filereadable('/tmp/chosenfile') - exec 'edit ' . system('cat /tmp/chosenfile') - call system('rm /tmp/chosenfile') +function! RangeChooser() + let temp = tempname() + " The option "--choosefiles" was added in ranger 1.5.1. Use the next line + " with ranger 1.4.2 through 1.5.0 instead. + "exec 'silent !ranger --choosefile=' . shellescape(temp) + exec 'silent !ranger --choosefiles=' . shellescape(temp) + if !filereadable(temp) + " Nothing to read. + return endif - redraw! -endfun -map ,r :call RangerChooser()<CR> + let names = readfile(temp) + if empty(names) + " Nothing to open. + return + endif + " Edit the first item. + exec 'edit ' . fnameescape(names[0]) + " Add any remaning items to the arg list/buffer list. + for name in names[1:] + exec 'argadd ' . fnameescape(name) + endfor +endfunction +command! -bar RangerChooser call RangeChooser() +nnoremap <leader>r :<C-U>RangerChooser<CR> |