summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/vim_file_chooser.vim38
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>
hut <hut@lavabit.com> 2011-10-05 18:15:35 +0200 committer hut <hut@lavabit.com> 2011-10-05 18:15:35 +0200 README: polished, removed INSTALL' href='/akspecs/ranger/commit/README?h=v1.9.3&id=240394a494b0bbb854687a34941bf90a5ccd5b4d'>240394a4 ^
03ed2a43 ^






2e74f350 ^
03ed2a43 ^
7bf5f967 ^
03ed2a43 ^
7dc8fef8 ^
4833bc23 ^

4ea0f69a ^

03ed2a43 ^
240394a4 ^
03dae5f0 ^

9a619526 ^
03dae5f0 ^
9e89f023 ^
36e4e71e ^
20ab9343 ^

20ab9343 ^





4ea0f69a ^

240394a4 ^
7dc8fef8 ^
36e4e71e ^

4a383291 ^
78a7d762 ^
e952d6cb ^
78a7d762 ^
03ed2a43 ^
4ea0f69a ^

7838675f ^

bc54f757 ^
6ff9bb6f ^
03ed2a43 ^
7838675f ^

2c8cb95f ^
03ed2a43 ^



1366ef67 ^
7838675f ^
03ed2a43 ^
2c8cb95f ^
03ed2a43 ^

ae99c2c9 ^
03ed2a43 ^
107b72e7 ^
03ed2a43 ^


08b08d70 ^
240394a4 ^



240394a4 ^
03ed2a43 ^
240394a4 ^

03ed2a43 ^


240394a4 ^

03ed2a43 ^


2c8cb95f ^
03ed2a43 ^
240394a4 ^

e5fb3d74 ^
240394a4 ^

03ed2a43 ^

7dc8fef8 ^


03ed2a43 ^
d9b5426e ^
78edc1ed ^
d9b5426e ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115