Move dir_up functionality into lib and make '-' a default keymap for it
This commit is contained in:
parent
361e20ecfa
commit
0a4123b71f
@ -62,6 +62,7 @@ let g:nvim_tree_bindings = {
|
||||
\ 'paste': 'p',
|
||||
\ 'prev_git_item': '[c',
|
||||
\ 'next_git_item': ']c',
|
||||
\ 'dir_up': '-',
|
||||
\ }
|
||||
|
||||
" Disable default mappings by plugin
|
||||
@ -113,6 +114,7 @@ highlight NvimTreeFolderIcon guibg=blue
|
||||
- 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
|
||||
- type '-' to naviate up to the parent directory of the current file/directory
|
||||
- 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
|
||||
|
||||
@ -195,6 +195,7 @@ INFORMATIONS *nvim-tree-info*
|
||||
- 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
|
||||
- type '-' to navigate up one directory
|
||||
|
||||
- if the file is a directory, '<CR>' will open the directory
|
||||
- otherwise it will open the file in the buffer near the tree
|
||||
@ -232,6 +233,7 @@ default keybindings will be applied to undefined keys.
|
||||
\ paste: 'p',
|
||||
\ prev_git_item: '[c',
|
||||
\ next_git_item: ']c',
|
||||
\ dir_up: '-',
|
||||
\ }
|
||||
|
||||
|Features| *nvim-tree-features*
|
||||
|
||||
@ -70,6 +70,7 @@ function M.get_bindings()
|
||||
paste = keybindings.paste or 'p',
|
||||
prev_git_item = keybindings.prev_git_item or '[c',
|
||||
next_git_item = keybindings.next_git_item or ']c',
|
||||
dir_up = keybindings.dir_up or '-',
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@ -252,6 +252,7 @@ local function set_mappings()
|
||||
[bindings.paste] = 'on_keypress("paste")';
|
||||
[bindings.prev_git_item] = 'on_keypress("prev_git_item")';
|
||||
[bindings.next_git_item] = 'on_keypress("next_git_item")';
|
||||
[bindings.dir_up] = 'on_keypress("dir_up")';
|
||||
gx = "xdg_open()";
|
||||
}
|
||||
|
||||
@ -366,4 +367,16 @@ function M.toggle_dotfiles()
|
||||
return M.refresh_tree()
|
||||
end
|
||||
|
||||
function M.dir_up(node)
|
||||
if not node then
|
||||
return M.change_dir('..')
|
||||
else
|
||||
local newdir = vim.fn.fnamemodify(node.absolute_path, ':h')
|
||||
if newdir == M.Tree.cwd then
|
||||
M.change_dir('..')
|
||||
end
|
||||
return M.set_index_and_redraw(newdir)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -73,6 +73,7 @@ local keypress_funcs = {
|
||||
refresh = lib.refresh_tree,
|
||||
prev_git_item = gen_go_to('prev_git_item'),
|
||||
next_git_item = gen_go_to('next_git_item'),
|
||||
dir_up = lib.dir_up,
|
||||
preview = function(node)
|
||||
if node.entries ~= nil or node.name == '..' then return end
|
||||
return lib.open_file('preview', node.absolute_path)
|
||||
@ -105,19 +106,6 @@ function M.on_keypress(mode)
|
||||
end
|
||||
end
|
||||
|
||||
function M.dir_up()
|
||||
local node = lib.get_node_at_cursor()
|
||||
if not node then
|
||||
return lib.change_dir('..')
|
||||
else
|
||||
local newdir = vim.fn.fnamemodify(node.absolute_path, ':h')
|
||||
if newdir == lib.Tree.cwd then
|
||||
lib.change_dir('..')
|
||||
end
|
||||
lib.set_index_and_redraw(newdir)
|
||||
end
|
||||
end
|
||||
|
||||
function M.refresh()
|
||||
lib.refresh_tree()
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user