Skip to content

Add mappings for jumping to previous or next git item. #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ let g:lua_tree_bindings = {
\ 'toggle_ignored': 'I',
\ 'preview': '<Tab>',
\ 'cd': '<C-]>',
\ '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
Expand Down Expand Up @@ -97,6 +105,8 @@ highlight LuaTreeFolderIcon guibg=blue
- type `c` to add/remove file/directory to copy clipboard
- type `p` to paste from clipboard. Cut clipboard has precedence over copy (will prompt for confirmation)
- type `d` to delete a file (will prompt for confirmation)
- type `]c` to go to next git item
- type `[c` to go to prev git item
- if the file is a directory, `<CR>` will open the directory otherwise it will open the file in the buffer near the tree
- if the file is a symlink, `<CR>` will follow the symlink (if the target is a file)
- `<C-v>` will open the file in a vertical split
Expand Down
28 changes: 16 additions & 12 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ INFORMATIONS *nvim-tree-info*
- type 'p' to paste from clipboard. Cut clipboard has precedence over copy
(will prompt for confirmation)
- type 'd' to delete a file (will prompt for confirmation)
- type ']c' to go to next git item
- type '[c' to go to prev git item

- if the file is a directory, '<CR>' will open the directory
- otherwise it will open the file in the buffer near the tree
Expand All @@ -166,18 +168,20 @@ you can change default keybindings by defining this variable.
default keybindings will be applied to undefined keys.
>
let g:lua_tree_bindings = {
\ edit: '<cr>',
\ edit_vsplit: '<c-v>',
\ edit_split: '<c-x>',
\ edit_tab: '<c-t>',
\ cd: '<c-]>',
\ preview: '<Tab>',
\ create: 'a',
\ remove: 'd',
\ rename: 'r',
\ cut: 'x',
\ copy: 'c',
\ paste: 'p',
\ edit: '<cr>',
\ edit_vsplit: '<c-v>',
\ edit_split: '<c-x>',
\ edit_tab: '<c-t>',
\ cd: '<c-]>',
\ preview: '<Tab>',
\ create: 'a',
\ remove: 'd',
\ rename: 'r',
\ cut: 'x',
\ copy: 'c',
\ paste: 'p',
\ prev_git_item: '[c',
\ next_git_item: ']c',
\ }

|Features| *nvim-tree-features*
Expand Down
2 changes: 2 additions & 0 deletions lua/lib/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function M.get_bindings()
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

Expand Down
2 changes: 2 additions & 0 deletions lua/lib/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ local function set_mappings()
[bindings.cut] = 'on_keypress("cut")';
[bindings.copy] = 'on_keypress("copy")';
[bindings.paste] = 'on_keypress("paste")';
[bindings.prev_git_item] = 'on_keypress("prev_git_item")';
[bindings.next_git_item] = 'on_keypress("next_git_item")';
gx = "xdg_open()";
}

Expand Down
21 changes: 21 additions & 0 deletions lua/tree.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local luv = vim.loop
local lib = require'lib.lib'
local config = require'lib.config'
local colors = require'lib.colors'
local renderer = require'lib.renderer'
local fs = require'lib.fs'
Expand Down Expand Up @@ -28,6 +29,18 @@ function M.open()
end
end

local function gen_go_to(mode)
local icon_state = config.get_icon_state()
local flags = mode == 'prev_git_item' and 'b' or ''
local icons = table.concat(vim.tbl_values(icon_state.icons.git_icons), '\\|')
return function()
return icon_state.show_git_icon and vim.fn.search(icons, flags)
end
end

local go_to_prev_git_item = gen_go_to('prev_git_item')
local go_to_next_git_item = gen_go_to('next_git_item')

function M.on_keypress(mode)
local node = lib.get_node_at_cursor()
if not node then return end
Expand Down Expand Up @@ -55,6 +68,14 @@ function M.on_keypress(mode)
return lib.toggle_ignored()
end

if mode == 'prev_git_item' then
return go_to_prev_git_item()
end

if mode == 'next_git_item' then
return go_to_next_git_item()
end

if node.name == ".." then
return lib.change_dir("..")
elseif mode == "cd" and node.entries ~= nil then
Expand Down