diff --git a/README.md b/README.md index b704b6eb..2e413d3c 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,8 @@ let g:lua_tree_bindings = { \ 'edit_vsplit': '', \ 'edit_split': '', \ 'edit_tab': '', - \ 'cd': '.', - \ 'create': 'a', - \ 'remove': 'd', - \ 'rename': 'r' - \ } - + \ 'preview': '', + \ 'cd': '', " default will show icon by default if no icon is provided " default shows no icon by default let g:lua_tree_icons = { @@ -85,19 +81,20 @@ highlight LuaTreeFolderIcon guibg=blue - move around like in any vim buffer - `` on `..` will cd in the above directory -- `.` will cd in the directory under the cursor +- `` will cd in the directory under the cursor - type `a` to add a file. Adding a directory requires leaving a leading `/` at the end of the path. > you can add multiple directories by doing foo/bar/baz/f and it will add foo bar and baz directories and f as a file - type `r` to rename a file - type `d` to delete a file (will prompt for confirmation) - if the file is a directory, `` will open the directory otherwise it will open the file in the buffer near the tree - if the file is a symlink, `` will follow the symlink (if the target is a file) -- type `` will open the file in a vertical split -- type `` will open the file in a horizontal split -- type `` will open the file in a new tab -- type `gx` to open the file with the `open` command on MACOS and `xdg-open` in linux +- `` will open the file in a vertical split +- `` will open the file in a horizontal split +- `` will open the file in a new tab +- `` will open the file as a preview (keeps the cursor in the tree) +- `gx` opens the file with the `open` command on MACOS and `xdg-open` in linux - Double left click acts like `` -- Double right click acts like `.` +- Double right click acts like `` ## Note diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 9ecbee57..3c2c2288 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -122,7 +122,7 @@ INFORMATIONS *nvim-tree-info* - move around like in any vim buffer - '' on '..' will cd in the above directory -- typing '.' will cd in the directory under the cursor +- typing '' will cd in the directory under the cursor - type 'a' to add a file - type 'r' to rename a file @@ -131,14 +131,15 @@ INFORMATIONS *nvim-tree-info* - if the file is a directory, '' will open the directory - otherwise it will open the file in the buffer near the tree - if the file is a symlink, '' will follow the symlink -- type '' will open the file in a vertical split -- type '' will open the file in a horizontal split -- type '' will open the file in a new tab -- type 'gx' to open the file with the `open` command on macos and `xdg-open` +- '' will open the file in a vertical split +- '' will open the file in a horizontal split +- '' will open the file in a new tab +- '' will open the file as a preview (keeps the cursor in the tree) +- 'gx' opens the file with the `open` command on macos and `xdg-open` on linux. - Double left click acts like '' -- Double right click acts like '.' +- Double right click acts like '' |g:lua_tree_bindings| *g:lua_tree_bindings* @@ -150,7 +151,8 @@ default keybindings will be applied to undefined keys. \ edit_vsplit: '', \ edit_split: '', \ edit_tab: '', - \ cd: '.', + \ cd: '', + \ preview: '', \ create: 'a', \ remove: 'd', \ rename: 'r' diff --git a/lua/lib/config.lua b/lua/lib/config.lua index f05cc734..59fffdd5 100644 --- a/lua/lib/config.lua +++ b/lua/lib/config.lua @@ -49,6 +49,7 @@ function M.get_bindings() edit_vsplit = keybindings.edit_vsplit or '', edit_split = keybindings.edit_split or '', edit_tab = keybindings.edit_tab or '', + preview = keybindings.preview or '', cd = keybindings.cd or '', create = keybindings.create or 'a', remove = keybindings.remove or 'd', diff --git a/lua/lib/tree.lua b/lua/lib/tree.lua index f6b07333..476dc69b 100644 --- a/lua/lib/tree.lua +++ b/lua/lib/tree.lua @@ -183,7 +183,16 @@ function M.open_file(mode, filename) else api.nvim_command('noautocmd wincmd l') end - api.nvim_command(string.format("%s %s", mode, filename)) + if mode == 'preview' then + api.nvim_command(string.format("edit %s", filename)) + if vim.g.lua_tree_side == 'right' then + api.nvim_command('noautocmd wincmd l') + else + api.nvim_command('noautocmd wincmd h') + end + else + api.nvim_command(string.format("%s %s", mode, filename)) + end end function M.change_dir(foldername) @@ -207,6 +216,7 @@ local function set_mappings() [bindings.create] = 'on_keypress("create")'; [bindings.remove] = 'on_keypress("remove")'; [bindings.rename] = 'on_keypress("rename")'; + [bindings.preview] = 'on_keypress("preview")'; gx = "xdg_open()"; } diff --git a/lua/tree.lua b/lua/tree.lua index 697d22cd..6e6f3c63 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -39,6 +39,11 @@ function M.on_keypress(mode) return fs.rename(node) end + if mode == 'preview' then + if node.entries ~= nil or node.name == '..' then return end + return tree.open_file(mode, node.absolute_path) + end + if node.name == ".." then return tree.change_dir("..") elseif mode == "cd" and node.entries ~= nil then @@ -49,6 +54,7 @@ function M.on_keypress(mode) if node.link_to then local stat = luv.fs_stat(node.link_to) + -- TODO: potentially CD here if stat.type == 'directory' then return end tree.open_file(mode, node.link_to) elseif node.entries ~= nil then