@@ -190,20 +190,29 @@ local function open_file_in_tab(filename)
190
190
if M .quit_on_open then
191
191
view .close ()
192
192
end
193
+ if require (' nvim-tree' ).config .experimental .open .relative_path then
194
+ filename = utils .path_relative (filename , vim .fn .getcwd ())
195
+ end
193
196
vim .cmd (" tabe " .. vim .fn .fnameescape (filename ))
194
197
end
195
198
196
199
local function drop (filename )
197
200
if M .quit_on_open then
198
201
view .close ()
199
202
end
203
+ if require (' nvim-tree' ).config .experimental .open .relative_path then
204
+ filename = utils .path_relative (filename , vim .fn .getcwd ())
205
+ end
200
206
vim .cmd (" drop " .. vim .fn .fnameescape (filename ))
201
207
end
202
208
203
209
local function tab_drop (filename )
204
210
if M .quit_on_open then
205
211
view .close ()
206
212
end
213
+ if require (' nvim-tree' ).config .experimental .open .relative_path then
214
+ filename = utils .path_relative (filename , vim .fn .getcwd ())
215
+ end
207
216
vim .cmd (" tab :drop " .. vim .fn .fnameescape (filename ))
208
217
end
209
218
@@ -310,8 +319,12 @@ local function open_in_new_window(filename, mode)
310
319
end
311
320
end
312
321
313
- -- TODO: nvim-tree 会改变当前目录, 调用结束前恢复
314
- local fname = utils .escape_special_chars (vim .fn .fnameescape (vim .fn .fnamemodify (filename , ' :.' )))
322
+ local fname
323
+ if require (' nvim-tree' ).config .experimental .open .relative_path then
324
+ fname = utils .escape_special_chars (vim .fn .fnameescape (utils .path_relative (filename , vim .fn .getcwd ())))
325
+ else
326
+ fname = utils .escape_special_chars (vim .fn .fnameescape (filename ))
327
+ end
315
328
316
329
local command
317
330
if create_new_window then
347
360
348
361
local function edit_in_current_buf (filename )
349
362
require (" nvim-tree.view" ).abandon_current_window ()
363
+ if require (' nvim-tree' ).config .experimental .open .relative_path then
364
+ filename = utils .path_relative (filename , vim .fn .getcwd ())
365
+ end
350
366
vim .cmd (" keepalt keepjumps edit " .. vim .fn .fnameescape (filename ))
351
367
end
352
368
0 commit comments