X3eRo0 / dired.nvim

Emacs dired like file manager for neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Search in dired buffer

Ghasak opened this issue · comments

Firstly, I'd like to convey my gratitude for creating such an exceptional plugin. I have been a longtime user of nvimtree, but I genuinely believe that your plugin has immense potential. I'm hopeful that you will continue to develop it, adding even more valuable features.

Issue Encountered

Currently, there seems to be an unexpected behavior when attempting to search within the dired buffer using the / key. For example, after invoking the :Dired command, when I press / to search within a directory containing numerous files and folders, it redirects me to the root directory of my system, which is not the desired outcome.

Feature Requests

  1. Buffer Search Capability: It would be immensely beneficial to be able to easily search within the dired buffer. then for the matching the cursor will jump to the dir name so easily hit enter.
  2. Intuitive Keybinding Support: While I've managed to create my own keybindings, as seen below, an integrated approach would certainly enhance user experience.
local M = {}

local function dired_key_mapping()
    local map = vim.api.nvim_buf_set_keymap
    local opt = { silent = true, noremap = true }

    -- Set buffer-local mappings for 'dired' filetype
    map(0, 'n', 'h', ':DiredGoBack<CR>', opt)
    map(0, 'n', 'l', ':DiredEnter<CR>', opt)
end

M.setup = function()
    vim.api.nvim_create_autocmd("FileType", {
        pattern = "dired",
        callback = dired_key_mapping
    })
end

return M
  1. Adding Block editing
  2. Adding support for nerd icons for the dired buffer
  3. Support for changing permission on fly

Thank you once again, and please keep up the excellent work!

commented

I'm glad you liked my plugin. Thank you so much for using it.

For your 1st Issue, I was able to test it on my machine and buffer searching with "/" just works out of the box. The plugin treats dired buffer as a normal buffer when it comes to navigation and searching stuff and when a user presses it calculates which file to navigate and tries to open a dired buffer for that directory or opens the file if its a regular file.

You can see the demo here. https://asciinema.org/a/615902 I recorded my terminal screen.

For your 2nd Issue, I will fix/improve the keybinding system as soon as I get time to work on this plugin again.

Thanks again for using this plugin. ❤️

Thank you very much,
It seems the problem is in my previous key mapping when I tried to add l and h, please could you suggest me how to use them?
Assume I need

 map(0, "n", "l", "<Plug>(dired_enter)", opt)
 map(0, "n", "h", "<Plug>(dired_back)", opt)

If I add these to the init.lua of your plugin source, then the search will not work correctly, I don't know why? especially if you hit /d then you go back to parent directory.
Right now, I have a temporary solution as

  -- ---------------------------------------------------
  --                For current dired
  -- ---------------------------------------------------
  vim.api.nvim_set_keymap("n", "<Leader>fj", ":Dired <CR>", { noremap = true, silent = false })
  local dired_group = vim.api.nvim_create_augroup("dired", { clear = true })

  -- Create a mapping function based on the buffer name
  local function dired_key_mapping()
    local map = vim.api.nvim_buf_set_keymap
    local opt = { silent = true, noremap = true }
    -- Check if the filetype is `dired`
    if vim.bo.filetype == "dired" then
      -- Set buffer-local mappings based on your requirements
      map(0, "n", "<C-h>", "<Plug>(dired_back)", opt)
      map(0, "n", "<C-l>", "<Plug>(dired_enter)", opt)
    end
  end
  -- This is a modern lua api for autocmd  that will check always for the FileType
  vim.api.nvim_create_autocmd("FileType", {
    pattern = "dired",
    callback = function()
      dired_key_mapping()
    end,
    group = dired_group,
  })

@Ghasak did you find a solution? I personally have no idea why setting custom keymaps would cause this behaviour. I think some other keybind is messing with Dired's keybind.

@Ghasak You can now specify custom keybinds in the config. Can you try if your issue has been resolved?