diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 99316b54e0b..e1649208f52 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -620,7 +620,13 @@ Following is the default configuration. See |nvim-tree-opts| for details. default_yes = false, }, }, - experimental = {}, + experimental = { + actions = { + open_file = { + relative_path = false, + }, + }, + }, log = { enable = false, truncate = false, @@ -1539,6 +1545,12 @@ Confirmation prompts. Experimental features that may become default or optional functionality. In the event of a problem please disable the experiment and raise an issue. + *nvim-tree.experimental.actions.open_file.relative_path* + Buffers opened by nvim-tree will use with relative paths instead of + absolute. + Execute |:ls| to see the paths of all open buffers. + Type: `boolean`, Default: `false` + ============================================================================== 5.20 OPTS: LOG *nvim-tree-opts-log* @@ -2774,6 +2786,7 @@ highlight group is not, hard linking as follows: > |nvim-tree.diagnostics.show_on_open_dirs| |nvim-tree.disable_netrw| |nvim-tree.experimental| +|nvim-tree.experimental.actions.open_file.relative_path| |nvim-tree.filesystem_watchers.debounce_delay| |nvim-tree.filesystem_watchers.enable| |nvim-tree.filesystem_watchers.ignore_dirs| diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 1b295da982c..343196a0f66 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -584,7 +584,13 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS default_yes = false, }, }, - experimental = {}, + experimental = { + actions = { + open_file = { + relative_path = false, + }, + }, + }, log = { enable = false, truncate = false, diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 39026253376..130106106cb 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -190,6 +190,9 @@ local function open_file_in_tab(filename) if M.quit_on_open then view.close() end + if M.relative_path then + filename = utils.path_relative(filename, vim.fn.getcwd()) + end vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end @@ -197,6 +200,9 @@ local function drop(filename) if M.quit_on_open then view.close() end + if M.relative_path then + filename = utils.path_relative(filename, vim.fn.getcwd()) + end vim.cmd("drop " .. vim.fn.fnameescape(filename)) end @@ -204,6 +210,9 @@ local function tab_drop(filename) if M.quit_on_open then view.close() end + if M.relative_path then + filename = utils.path_relative(filename, vim.fn.getcwd()) + end vim.cmd("tab :drop " .. vim.fn.fnameescape(filename)) end @@ -310,7 +319,12 @@ local function open_in_new_window(filename, mode) end end - local fname = utils.escape_special_chars(vim.fn.fnameescape(filename)) + local fname + if M.relative_path then + fname = utils.escape_special_chars(vim.fn.fnameescape(utils.path_relative(filename, vim.fn.getcwd()))) + else + fname = utils.escape_special_chars(vim.fn.fnameescape(filename)) + end local command if create_new_window then @@ -346,6 +360,9 @@ end local function edit_in_current_buf(filename) require("nvim-tree.view").abandon_current_window() + if M.relative_path then + filename = utils.path_relative(filename, vim.fn.getcwd()) + end vim.cmd("keepalt keepjumps edit " .. vim.fn.fnameescape(filename)) end @@ -402,6 +419,7 @@ end function M.setup(opts) M.quit_on_open = opts.actions.open_file.quit_on_open M.resize_window = opts.actions.open_file.resize_window + M.relative_path = opts.experimental.actions.open_file.relative_path if opts.actions.open_file.window_picker.chars then opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper() end