diff options
author | hut <hut@lepus.uberspace.de> | 2015-04-13 12:49:49 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2015-04-13 12:49:49 +0200 |
commit | c0f2fc72eccb4127fba5f48ce4b422487d6ec752 (patch) | |
tree | 025f72dde6f7a7e5cdca82637da4e5dcef0ddd62 /examples/vim_file_chooser.vim | |
parent | a9bbdc440c2ea33ccc4470e00949ffa16ce2300e (diff) | |
download | ranger-c0f2fc72eccb4127fba5f48ce4b422487d6ec752.tar.gz |
moved "doc/examples" to "examples" for more visibility
Diffstat (limited to 'examples/vim_file_chooser.vim')
-rw-r--r-- | examples/vim_file_chooser.vim | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/vim_file_chooser.vim b/examples/vim_file_chooser.vim new file mode 100644 index 00000000..aa3af763 --- /dev/null +++ b/examples/vim_file_chooser.vim @@ -0,0 +1,36 @@ +" Compatible with ranger 1.4.2 through 1.6.* +" +" Add ranger as a file chooser in vim +" +" If you add this code to the .vimrc, ranger can be started using the command +" ":RangerChooser" 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. + +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) + redraw! + " Nothing to read. + return + endif + let names = readfile(temp) + if empty(names) + redraw! + " 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 + redraw! +endfunction +command! -bar RangerChooser call RangeChooser() +nnoremap <leader>r :<C-U>RangerChooser<CR> |