Skip to content

Commit 4f86707

Browse files
Add mapping for toggling ignored folders visibility.
1 parent 20f39a9 commit 4f86707

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ let g:lua_tree_show_icons = {
4444
" You don't have to define all keys.
4545
" NOTE: the 'edit' key will wrap/unwrap a folder and open a file
4646
let g:lua_tree_bindings = {
47-
\ 'edit': '<CR>',
48-
\ 'edit_vsplit': '<C-v>',
49-
\ 'edit_split': '<C-x>',
50-
\ 'edit_tab': '<C-t>',
51-
\ 'preview': '<Tab>',
52-
\ 'cd': '<C-]>',
47+
\ 'edit': '<CR>',
48+
\ 'edit_vsplit': '<C-v>',
49+
\ 'edit_split': '<C-x>',
50+
\ 'edit_tab': '<C-t>',
51+
\ 'toggle_ignored': 'I',
52+
\ 'preview': '<Tab>',
53+
\ 'cd': '<C-]>',
5354
}
5455
5556
" Disable default mappings by plugin
@@ -99,6 +100,7 @@ highlight LuaTreeFolderIcon guibg=blue
99100
- `<C-x>` will open the file in a horizontal split
100101
- `<C-t>` will open the file in a new tab
101102
- `<Tab>` will open the file as a preview (keeps the cursor in the tree)
103+
- `I` will toggle visibility of folders hidden via |g:lua_tree_ignore|
102104
- `gx` opens the file with the `open` command on MACOS and `xdg-open` in linux
103105
- Double left click acts like `<CR>`
104106
- Double right click acts like `<C-]>`

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ INFORMATIONS *nvim-tree-info*
145145
- '<C-x>' will open the file in a horizontal split
146146
- '<C-t>' will open the file in a new tab
147147
- '<Tab>' will open the file as a preview (keeps the cursor in the tree)
148+
- 'I' will toggle visibility of folders hidden via |g:lua_tree_ignore|
148149
- 'gx' opens the file with the `open` command on macos and `xdg-open`
149150
on linux.
150151

lua/lib/config.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ end
4545
function M.get_bindings()
4646
local keybindings = vim.g.lua_tree_bindings or {}
4747
return {
48-
edit = keybindings.edit or '<CR>',
49-
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
50-
edit_split = keybindings.edit_split or '<C-x>',
51-
edit_tab = keybindings.edit_tab or '<C-t>',
52-
preview = keybindings.preview or '<Tab>',
53-
cd = keybindings.cd or '<C-]>',
54-
create = keybindings.create or 'a',
55-
remove = keybindings.remove or 'd',
56-
rename = keybindings.rename or 'r',
48+
edit = keybindings.edit or '<CR>',
49+
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
50+
edit_split = keybindings.edit_split or '<C-x>',
51+
edit_tab = keybindings.edit_tab or '<C-t>',
52+
preview = keybindings.preview or '<Tab>',
53+
toggle_ignored = keybindings.toggle_ignored or 'I',
54+
cd = keybindings.cd or '<C-]>',
55+
create = keybindings.create or 'a',
56+
remove = keybindings.remove or 'd',
57+
rename = keybindings.rename or 'r',
5758
}
5859
end
5960

lua/lib/lib.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ local function set_mappings()
205205
[bindings.edit_vsplit] = 'on_keypress("vsplit")';
206206
[bindings.edit_split] = 'on_keypress("split")';
207207
[bindings.edit_tab] = 'on_keypress("tabnew")';
208+
[bindings.toggle_ignored] = 'on_keypress("toggle_ignored")';
208209
[bindings.create] = 'on_keypress("create")';
209210
[bindings.remove] = 'on_keypress("remove")';
210211
[bindings.rename] = 'on_keypress("rename")';
@@ -278,4 +279,9 @@ function M.win_open()
278279
return false
279280
end
280281

282+
function M.toggle_ignored()
283+
pops.show_ignored = not pops.show_ignored
284+
return M.refresh_tree()
285+
end
286+
281287
return M

lua/lib/populate.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ local icon_config = config.get_icon_state()
55
local api = vim.api
66
local luv = vim.loop
77

8-
local M = {}
8+
local M = {
9+
show_ignored = false
10+
}
911

1012
local path_to_matching_str = require'lib.utils'.path_to_matching_str
1113

@@ -63,7 +65,7 @@ local function gen_ignore_check()
6365
end
6466

6567
return function(path)
66-
return ignore_list[path] == true
68+
return not M.show_ignored and ignore_list[path] == true
6769
end
6870
end
6971

lua/tree.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ function M.on_keypress(mode)
4545
return lib.open_file(mode, node.absolute_path)
4646
end
4747

48+
if mode == 'toggle_ignored' then
49+
return lib.toggle_ignored()
50+
end
51+
4852
if node.name == ".." then
4953
return lib.change_dir("..")
5054
elseif mode == "cd" and node.entries ~= nil then

0 commit comments

Comments
 (0)