diff --git a/README.md b/README.md index e92791cc..6290062e 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ let g:lua_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR let g:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window let g:lua_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer let g:lua_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open +let g:lua_tree_hide_dotfiles = 1 "0 by default, this option hides files and folders starting with a dot `.` let g:lua_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons). let g:lua_tree_show_icons = { \ 'git': 1, @@ -45,21 +46,22 @@ let g:lua_tree_show_icons = { " You don't have to define all keys. " NOTE: the 'edit' key will wrap/unwrap a folder and open a file let g:lua_tree_bindings = { - \ 'edit': '', - \ 'edit_vsplit': '', - \ 'edit_split': '', - \ 'edit_tab': '', - \ 'toggle_ignored': 'I', - \ 'preview': '', - \ 'cd': '', - \ 'create': 'a', - \ 'remove': 'd', - \ 'rename': 'r', - \ 'cut': 'x', - \ 'copy': 'c', - \ 'paste': 'p', - \ 'prev_git_item': '[c', - \ 'next_git_item': ']c', + \ 'edit': '', + \ 'edit_vsplit': '', + \ 'edit_split': '', + \ 'edit_tab': '', + \ 'toggle_ignored': 'I', + \ 'toggle_dotfiles': 'H', + \ 'preview': '', + \ 'cd': '', + \ 'create': 'a', + \ 'remove': 'd', + \ 'rename': 'r', + \ 'cut': 'x', + \ 'copy': 'c', + \ 'paste': 'p', + \ 'prev_git_item': '[c', + \ 'next_git_item': ']c', } " Disable default mappings by plugin @@ -115,6 +117,7 @@ highlight LuaTreeFolderIcon guibg=blue - `` will open the file in a new tab - `` will open the file as a preview (keeps the cursor in the tree) - `I` will toggle visibility of folders hidden via |g:lua_tree_ignore| +- `H` will toggle visibility of dotfiles (files/folders starting with a `.`) - `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 `` diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index f0f4416e..6386c7b8 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -138,6 +138,13 @@ Default is 0 |g:lua_tree_indent_markers| *g:lua_tree_indent_markers* Can be `0` or `1`. When `1`, will display indent markers when folders are open +Default is 0 + +|g:lua_tree_hide_dotfiles| *g:lua_tree_hide_dotfiles* + +Can be `0` or `1`. When `1`, will hide dotfiles, files or folders which start +with the `.` character. +Default is 0 ============================================================================== INFORMATIONS *nvim-tree-info* diff --git a/doc/tags b/doc/tags index e33d2b37..dff2d3df 100644 --- a/doc/tags +++ b/doc/tags @@ -14,6 +14,7 @@ g:lua_tree_icons nvim-tree-lua.txt /*g:lua_tree_icons* g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore* g:lua_tree_indent_markers nvim-tree-lua.txt /*g:lua_tree_indent_markers* g:lua_tree_show_icons nvim-tree-lua.txt /*g:lua_tree_show_icons* +g:lua_tree_hide_dotfiles nvim-tree-lua.txt /*g:lua_tree_hide_dotfiles* g:lua_tree_side nvim-tree-lua.txt /*g:lua_tree_side* g:lua_tree_size nvim-tree-lua.txt /*g:lua_tree_size* lua_tree_highlight nvim-tree-lua.txt /*lua_tree_highlight* diff --git a/lua/lib/config.lua b/lua/lib/config.lua index 6284f95a..6fd6a2d2 100644 --- a/lua/lib/config.lua +++ b/lua/lib/config.lua @@ -45,22 +45,23 @@ end function M.get_bindings() local keybindings = vim.g.lua_tree_bindings or {} return { - edit = keybindings.edit or '', - edit_vsplit = keybindings.edit_vsplit or '', - edit_split = keybindings.edit_split or '', - edit_tab = keybindings.edit_tab or '', - preview = keybindings.preview or '', - toggle_ignored = keybindings.toggle_ignored or 'I', - refresh = keybindings.refresh or 'R', - cd = keybindings.cd or '', - create = keybindings.create or 'a', - remove = keybindings.remove or 'd', - rename = keybindings.rename or 'r', - cut = keybindings.cut or 'x', - copy = keybindings.copy or 'c', - paste = keybindings.paste or 'p', - prev_git_item = keybindings.prev_git_item or '[c', - next_git_item = keybindings.next_git_item or ']c', + edit = keybindings.edit or '', + edit_vsplit = keybindings.edit_vsplit or '', + edit_split = keybindings.edit_split or '', + edit_tab = keybindings.edit_tab or '', + preview = keybindings.preview or '', + toggle_ignored = keybindings.toggle_ignored or 'I', + toggle_dotfiles = keybindings.toggle_dotfiles or 'H', + refresh = keybindings.refresh or 'R', + cd = keybindings.cd or '', + create = keybindings.create or 'a', + remove = keybindings.remove or 'd', + rename = keybindings.rename or 'r', + cut = keybindings.cut or 'x', + copy = keybindings.copy or 'c', + paste = keybindings.paste or 'p', + prev_git_item = keybindings.prev_git_item or '[c', + next_git_item = keybindings.next_git_item or ']c', } end diff --git a/lua/lib/lib.lua b/lua/lib/lib.lua index f585392f..00280e57 100644 --- a/lua/lib/lib.lua +++ b/lua/lib/lib.lua @@ -224,6 +224,7 @@ local function set_mappings() [bindings.edit_split] = 'on_keypress("split")'; [bindings.edit_tab] = 'on_keypress("tabnew")'; [bindings.toggle_ignored] = 'on_keypress("toggle_ignored")'; + [bindings.toggle_dotfiles] = 'on_keypress("toggle_dotfiles")'; [bindings.refresh] = 'on_keypress("refresh")'; [bindings.create] = 'on_keypress("create")'; [bindings.remove] = 'on_keypress("remove")'; @@ -304,4 +305,9 @@ function M.toggle_ignored() return M.refresh_tree() end +function M.toggle_dotfiles() + pops.show_dotfiles = not pops.show_dotfiles + return M.refresh_tree() +end + return M diff --git a/lua/lib/populate.lua b/lua/lib/populate.lua index 480096c7..4f022c9a 100644 --- a/lua/lib/populate.lua +++ b/lua/lib/populate.lua @@ -6,7 +6,8 @@ local api = vim.api local luv = vim.loop local M = { - show_ignored = false + show_ignored = false, + show_dotfiles = vim.g.lua_tree_hide_dotfiles ~= 1, } local path_to_matching_str = require'lib.utils'.path_to_matching_str @@ -65,7 +66,9 @@ local function gen_ignore_check() end return function(path) - return not M.show_ignored and ignore_list[path] == true + local ignore_path = not M.show_ignored and ignore_list[path] == true + local ignore_dotfiles = not M.show_dotfiles and path:sub(1, 1) == '.' + return ignore_path or ignore_dotfiles end end diff --git a/lua/tree.lua b/lua/tree.lua index 64ea5097..cb731bce 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -46,6 +46,7 @@ local keypress_funcs = { cut = fs.cut, paste = fs.paste, toggle_ignored = lib.toggle_ignored, + toggle_dotfiles = lib.toggle_dotfiles, refresh = lib.refresh_tree, prev_git_item = gen_go_to('prev_git_item'), next_git_item = gen_go_to('next_git_item'),