Skip to content

Commit 387c9de

Browse files
authored
Merge pull request #56 from kristijanhusak/feature/go-to-git-items
Add mappings for jumping to previous or next git item.
2 parents 7743d90 + 28c300a commit 387c9de

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ let g:lua_tree_bindings = {
5151
\ 'toggle_ignored': 'I',
5252
\ 'preview': '<Tab>',
5353
\ 'cd': '<C-]>',
54+
\ 'create': 'a',
55+
\ 'remove': 'd',
56+
\ 'rename': 'r',
57+
\ 'cut': 'x',
58+
\ 'copy': 'c',
59+
\ 'paste': 'p',
60+
\ 'prev_git_item': '[c',
61+
\ 'next_git_item': ']c',
5462
}
5563
5664
" Disable default mappings by plugin
@@ -97,6 +105,8 @@ highlight LuaTreeFolderIcon guibg=blue
97105
- type `c` to add/remove file/directory to copy clipboard
98106
- type `p` to paste from clipboard. Cut clipboard has precedence over copy (will prompt for confirmation)
99107
- type `d` to delete a file (will prompt for confirmation)
108+
- type `]c` to go to next git item
109+
- type `[c` to go to prev git item
100110
- if the file is a directory, `<CR>` will open the directory otherwise it will open the file in the buffer near the tree
101111
- if the file is a symlink, `<CR>` will follow the symlink (if the target is a file)
102112
- `<C-v>` will open the file in a vertical split

doc/nvim-tree-lua.txt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ INFORMATIONS *nvim-tree-info*
145145
- type 'p' to paste from clipboard. Cut clipboard has precedence over copy
146146
(will prompt for confirmation)
147147
- type 'd' to delete a file (will prompt for confirmation)
148+
- type ']c' to go to next git item
149+
- type '[c' to go to prev git item
148150

149151
- if the file is a directory, '<CR>' will open the directory
150152
- otherwise it will open the file in the buffer near the tree
@@ -166,18 +168,20 @@ you can change default keybindings by defining this variable.
166168
default keybindings will be applied to undefined keys.
167169
>
168170
let g:lua_tree_bindings = {
169-
\ edit: '<cr>',
170-
\ edit_vsplit: '<c-v>',
171-
\ edit_split: '<c-x>',
172-
\ edit_tab: '<c-t>',
173-
\ cd: '<c-]>',
174-
\ preview: '<Tab>',
175-
\ create: 'a',
176-
\ remove: 'd',
177-
\ rename: 'r',
178-
\ cut: 'x',
179-
\ copy: 'c',
180-
\ paste: 'p',
171+
\ edit: '<cr>',
172+
\ edit_vsplit: '<c-v>',
173+
\ edit_split: '<c-x>',
174+
\ edit_tab: '<c-t>',
175+
\ cd: '<c-]>',
176+
\ preview: '<Tab>',
177+
\ create: 'a',
178+
\ remove: 'd',
179+
\ rename: 'r',
180+
\ cut: 'x',
181+
\ copy: 'c',
182+
\ paste: 'p',
183+
\ prev_git_item: '[c',
184+
\ next_git_item: ']c',
181185
\ }
182186
183187
|Features| *nvim-tree-features*

lua/lib/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ function M.get_bindings()
5858
cut = keybindings.cut or 'x',
5959
copy = keybindings.copy or 'c',
6060
paste = keybindings.paste or 'p',
61+
prev_git_item = keybindings.prev_git_item or '[c',
62+
next_git_item = keybindings.next_git_item or ']c',
6163
}
6264
end
6365

lua/lib/lib.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ local function set_mappings()
213213
[bindings.cut] = 'on_keypress("cut")';
214214
[bindings.copy] = 'on_keypress("copy")';
215215
[bindings.paste] = 'on_keypress("paste")';
216+
[bindings.prev_git_item] = 'on_keypress("prev_git_item")';
217+
[bindings.next_git_item] = 'on_keypress("next_git_item")';
216218
gx = "xdg_open()";
217219
}
218220

lua/tree.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local luv = vim.loop
22
local lib = require'lib.lib'
3+
local config = require'lib.config'
34
local colors = require'lib.colors'
45
local renderer = require'lib.renderer'
56
local fs = require'lib.fs'
@@ -28,6 +29,18 @@ function M.open()
2829
end
2930
end
3031

32+
local function gen_go_to(mode)
33+
local icon_state = config.get_icon_state()
34+
local flags = mode == 'prev_git_item' and 'b' or ''
35+
local icons = table.concat(vim.tbl_values(icon_state.icons.git_icons), '\\|')
36+
return function()
37+
return icon_state.show_git_icon and vim.fn.search(icons, flags)
38+
end
39+
end
40+
41+
local go_to_prev_git_item = gen_go_to('prev_git_item')
42+
local go_to_next_git_item = gen_go_to('next_git_item')
43+
3144
function M.on_keypress(mode)
3245
local node = lib.get_node_at_cursor()
3346
if not node then return end
@@ -55,6 +68,14 @@ function M.on_keypress(mode)
5568
return lib.toggle_ignored()
5669
end
5770

71+
if mode == 'prev_git_item' then
72+
return go_to_prev_git_item()
73+
end
74+
75+
if mode == 'next_git_item' then
76+
return go_to_next_git_item()
77+
end
78+
5879
if node.name == ".." then
5980
return lib.change_dir("..")
6081
elseif mode == "cd" and node.entries ~= nil then

0 commit comments

Comments
 (0)