Add mappings for jumping to previous or next git item.
This commit is contained in:
10
README.md
10
README.md
@@ -51,6 +51,14 @@ let g:lua_tree_bindings = {
|
|||||||
\ 'toggle_ignored': 'I',
|
\ 'toggle_ignored': 'I',
|
||||||
\ 'preview': '<Tab>',
|
\ 'preview': '<Tab>',
|
||||||
\ 'cd': '<C-]>',
|
\ '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
|
" Disable default mappings by plugin
|
||||||
@@ -97,6 +105,8 @@ highlight LuaTreeFolderIcon guibg=blue
|
|||||||
- type `c` to add/remove file/directory to copy clipboard
|
- 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 `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 `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 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)
|
- 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
|
- `<C-v>` will open the file in a vertical split
|
||||||
|
|||||||
@@ -145,6 +145,8 @@ INFORMATIONS *nvim-tree-info*
|
|||||||
- type 'p' to paste from clipboard. Cut clipboard has precedence over copy
|
- type 'p' to paste from clipboard. Cut clipboard has precedence over copy
|
||||||
(will prompt for confirmation)
|
(will prompt for confirmation)
|
||||||
- type 'd' to delete a file (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
|
- if the file is a directory, '<CR>' will open the directory
|
||||||
- otherwise it will open the file in the buffer near the tree
|
- 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.
|
|||||||
default keybindings will be applied to undefined keys.
|
default keybindings will be applied to undefined keys.
|
||||||
>
|
>
|
||||||
let g:lua_tree_bindings = {
|
let g:lua_tree_bindings = {
|
||||||
\ edit: '<cr>',
|
\ edit: '<cr>',
|
||||||
\ edit_vsplit: '<c-v>',
|
\ edit_vsplit: '<c-v>',
|
||||||
\ edit_split: '<c-x>',
|
\ edit_split: '<c-x>',
|
||||||
\ edit_tab: '<c-t>',
|
\ edit_tab: '<c-t>',
|
||||||
\ cd: '<c-]>',
|
\ cd: '<c-]>',
|
||||||
\ preview: '<Tab>',
|
\ preview: '<Tab>',
|
||||||
\ create: 'a',
|
\ create: 'a',
|
||||||
\ remove: 'd',
|
\ remove: 'd',
|
||||||
\ rename: 'r',
|
\ rename: 'r',
|
||||||
\ cut: 'x',
|
\ cut: 'x',
|
||||||
\ copy: 'c',
|
\ copy: 'c',
|
||||||
\ paste: 'p',
|
\ paste: 'p',
|
||||||
|
\ prev_git_item: '[c',
|
||||||
|
\ next_git_item: ']c',
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
|Features| *nvim-tree-features*
|
|Features| *nvim-tree-features*
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ function M.get_bindings()
|
|||||||
cut = keybindings.cut or 'x',
|
cut = keybindings.cut or 'x',
|
||||||
copy = keybindings.copy or 'c',
|
copy = keybindings.copy or 'c',
|
||||||
paste = keybindings.paste or 'p',
|
paste = keybindings.paste or 'p',
|
||||||
|
prev_git_item = keybindings.prev_git_item or '[c',
|
||||||
|
next_git_item = keybindings.next_git_item or ']c',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -213,6 +213,8 @@ local function set_mappings()
|
|||||||
[bindings.cut] = 'on_keypress("cut")';
|
[bindings.cut] = 'on_keypress("cut")';
|
||||||
[bindings.copy] = 'on_keypress("copy")';
|
[bindings.copy] = 'on_keypress("copy")';
|
||||||
[bindings.paste] = 'on_keypress("paste")';
|
[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()";
|
gx = "xdg_open()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
20
lua/tree.lua
20
lua/tree.lua
@@ -1,5 +1,6 @@
|
|||||||
local luv = vim.loop
|
local luv = vim.loop
|
||||||
local lib = require'lib.lib'
|
local lib = require'lib.lib'
|
||||||
|
local config = require'lib.config'
|
||||||
local colors = require'lib.colors'
|
local colors = require'lib.colors'
|
||||||
local renderer = require'lib.renderer'
|
local renderer = require'lib.renderer'
|
||||||
local fs = require'lib.fs'
|
local fs = require'lib.fs'
|
||||||
@@ -28,6 +29,21 @@ function M.open()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function go_to_git_item(mode)
|
||||||
|
local icon_state = config.get_icon_state()
|
||||||
|
if not icon_state.show_git_icon then return end
|
||||||
|
|
||||||
|
local icons = {}
|
||||||
|
for _, icon in pairs(icon_state.icons.git_icons) do
|
||||||
|
table.insert(icons, icon)
|
||||||
|
end
|
||||||
|
|
||||||
|
icons = table.concat(icons, '\\|')
|
||||||
|
local flags = mode == 'prev_git_item' and 'b' or ''
|
||||||
|
return vim.fn.search(icons, flags)
|
||||||
|
end
|
||||||
|
|
||||||
function M.on_keypress(mode)
|
function M.on_keypress(mode)
|
||||||
local node = lib.get_node_at_cursor()
|
local node = lib.get_node_at_cursor()
|
||||||
if not node then return end
|
if not node then return end
|
||||||
@@ -55,6 +71,10 @@ function M.on_keypress(mode)
|
|||||||
return lib.toggle_ignored()
|
return lib.toggle_ignored()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if mode == 'next_git_item' or mode == 'prev_git_item' then
|
||||||
|
return go_to_git_item(mode)
|
||||||
|
end
|
||||||
|
|
||||||
if node.name == ".." then
|
if node.name == ".." then
|
||||||
return lib.change_dir("..")
|
return lib.change_dir("..")
|
||||||
elseif mode == "cd" and node.entries ~= nil then
|
elseif mode == "cd" and node.entries ~= nil then
|
||||||
|
|||||||
Reference in New Issue
Block a user