summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorIsrael Chauca Fuentes <israelvarios@fastmail.fm>2013-09-17 23:51:43 -0400
committerIsrael Chauca Fuentes <israelvarios@fastmail.fm>2013-09-17 23:51:43 -0400
commitee35f41d6b41dbf71cb558ecd8c69883738ff98a (patch)
tree35a7916078a9c73c2e3386c0fcdb7a54d8eadbd6 /doc
parent75533afccc5e96b231565adba923ba373cba2c6f (diff)
downloadranger-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')
-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>
mp;id=a654e4ecace2d506d1b10f1dde2c287ebe84ef37'>a654e4ec ^
672e3e50 ^

a654e4ec ^





672e3e50 ^

a654e4ec ^
672e3e50 ^





4690ce81 ^
32b8fac2 ^



672e3e50 ^

4690ce81 ^
32b8fac2 ^
a654e4ec ^

32b8fac2 ^
672e3e50 ^

4690ce81 ^
32b8fac2 ^

a654e4ec ^

4690ce81 ^
672e3e50 ^

76755b28 ^
672e3e50 ^


76755b28 ^
672e3e50 ^

d5d908dd ^
672e3e50 ^
76755b28 ^

672e3e50 ^

4690ce81 ^
76755b28 ^

a654e4ec ^
4690ce81 ^

a654e4ec ^
4690ce81 ^

76755b28 ^
4690ce81 ^
76755b28 ^

32b8fac2 ^
76755b28 ^
32b8fac2 ^


76755b28 ^


4690ce81 ^

672e3e50 ^

4690ce81 ^



dcc060c7 ^

4690ce81 ^
dcc060c7 ^
4690ce81 ^
9542bb11 ^

76755b28 ^
4690ce81 ^

672e3e50 ^

dcc060c7 ^
672e3e50 ^






a654e4ec ^

4690ce81 ^

672e3e50 ^

76755b28 ^
4690ce81 ^
a654e4ec ^
672e3e50 ^
d5d908dd ^
4690ce81 ^
d5d908dd ^

672e3e50 ^




a654e4ec ^
4690ce81 ^


a654e4ec ^
4690ce81 ^
672e3e50 ^
4690ce81 ^

672e3e50 ^







a654e4ec ^
4690ce81 ^



672e3e50 ^
dcc060c7 ^

672e3e50 ^

76755b28 ^
a654e4ec ^

4690ce81 ^
76755b28 ^
4690ce81 ^

9542bb11 ^

4690ce81 ^
672e3e50 ^
76755b28 ^
672e3e50 ^
4690ce81 ^




a654e4ec ^
4690ce81 ^


672e3e50 ^


a654e4ec ^
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197