Coder Social home page Coder Social logo

dired.nvim's Introduction

dired.nvim

A file browser inspired from Emacs Dired for neovim.

Screenshots

output

Different types of files in dired.nvim Screenshot from 2023-02-02 20-16-20 Screenshot from 2023-02-02 20-15-57

Installation

Requires Neovim 0.6 or higher.

Packer.nvim

use {
    "X3eRo0/dired.nvim",
    requires = "MunifTanjim/nui.nvim",
    config = function()
        require("dired").setup {
            path_separator = "/",
            show_banner = false,
            show_icons = false,
            show_hidden = true,
            show_dot_dirs = true,
            show_colors = true,
        }
    end
}

Setup

You can require this plugin and use it like this.

-- Neovim configuration for the 'dired' plugin

-- Set up the 'dired' plugin with custom options
require("dired").setup({
    path_separator = "/",                -- Use '/' as the path separator
    show_hidden = true,                  -- Show hidden files
    show_icons = false,                  -- Show icons (patched font required)
    show_banner = false,                 -- Do not show the banner
    hide_details = false,                -- Show file details by default
    sort_order = "name",                 -- Sort files by name by default

    -- Define keybindings for various 'dired' actions
    keybinds = {
        dired_enter = "<cr>",
        dired_back = "-",
        dired_up = "_",
        dired_rename = "R",
        -- ... (add more keybindings as needed)
        dired_quit = "q",
    },

    -- Define colors for different file types and attributes
    colors = {
        DiredDimText = { link = {}, bg = "NONE", fg = "505050", gui = "NONE" },
        DiredDirectoryName = { link = {}, bg = "NONE", fg = "9370DB", gui = "NONE" },
        -- ... (define more colors as needed)
        DiredMoveFile = { link = {}, bg = "NONE", fg = "ff3399", gui = "bold" },
    },
})

Usage

Run the command :Dired to open a buffer for your current directory. Press - in any buffer to open a directory buffer for its parent. Editing a directory will also open up a buffer, overriding Netrw.

Commands

You can use the following commands to add in your custom keybinds.

Command Description
Dired Open Dired UI (dir completion)
DiredRename Rename file/directory under cursor (file completion)
DiredDelete Delete file/directory under cursor (file completion)
DiredMark Mark file/directory under cursor (file completion)
DiredDeleteRange Delete selected files/directories (visual)
DiredDeleteMarked Delete marked files/directories
DiredMarkRange Mark a range of files/directories (visual)
DiredGoBack Navigate back in the directory history
DiredGoUp Move up to the parent directory
DiredCopy Copy the file/directory under the cursor
DiredCopyRange Copy selected files/directories (visual)
DiredCopyMarked Copy marked files/directories
DiredMove Move the file/directory under the cursor
DiredMoveRange Move selected files/directories (visual)
DiredMoveMarked Move marked files/directories
DiredPaste Paste copied or moved files in the current directory
DiredEnter Open the file or directory at the cursor
DiredCreate Create a new directory
DiredToggleHidden Toggle the visibility of hidden files
DiredToggleSortOrder Toggle the sorting order of files and directories
DiredToggleColors Toggle the display of colors
DiredToggleIcons Toggle the display of filetype icons
DiredToggleHideDetails Toggle hiding/showing file details
DiredQuit Quit the 'dired' interface

Keybinding

Inside a directory buffer, there are the following keybindings:

Keybinding Description
<CR> Open the file or directory at the cursor.
d Create new directories and files.
M Mark directories and files (both in normal and visual mode).
C Copy files.
X Move files.
P Paste files in the current directory.
D Delete directories and files (both in normal and visual mode).
R Rename directories and files.
MD Delete marked files.
MC Copy marked files.
MX Move marked files.
- Open the parent directory.
. Toggle show_hidden.
, Change sort_order.
c Toggle colors.
_ Move selection up one line.
, Toggle color display.
* Toggle filetype icons.
( Toggle hiding/showing file details.
q Quit the 'dired' interface.

The default keybinds are given below.

{
    dired_enter = "<cr>",
    dired_back = "-",
    dired_up = "_",
    dired_rename = "R",
    dired_create = "d",
    dired_delete = "D",
    dired_delete_range = "D",
    dired_copy = "C",
    dired_copy_range = "C",
    dired_copy_marked = "MC",
    dired_move = "X",
    dired_move_range = "X",
    dired_move_marked = "MX",
    dired_paste = "P",
    dired_mark = "M",
    dired_mark_range = "M",
    dired_delete_marked = "MD",
    dired_toggle_hidden = ".",
    dired_toggle_sort_order = ",",
    dired_toggle_icons = "*",
    dired_toggle_colors = "c",
    dired_toggle_hide_details = "(",
    dired_quit = "q",
}

Colors

You can change the colors of each component in the output by specifiying a table of options for each Hightlight group used in Dired.

local DiredDimText = {
    link = {},
    bg = "232323",
    fg = "f3f3f3"
    gui = "bold",
}

The options are explained below.

Option Descript
link A list of highlight groups to link to, in order of priority. The first one that exists will be used.
bg The background color to use, in hex, if the highlight group is not defined and it is not linked to another group.
fg The foreground color to use, in hex, if the highlight group is not defined and it is not linked to another group.
gui The gui to use, if the highlight group is not defined and it is not linked to another group.

The gui arg is described in syntax.txt and valid arguments are defined in attr-list :h attr-list

gui={attr-list}
	These give the attributes to use in the GUI mode.
	See |attr-list| for a description.
	Note that "bold" can be used here and by using a bold font.  They
	have the same effect.
	Note that the attributes are ignored for the "Normal" group.

attr-list is a comma-separated list (without spaces) of the following items (in any order):

Option Description
bold
underline
undercurl curly underline
underdouble double underline
underdotted dotted underline
underdashed dashed underline
strikethrough
reverse
inverse same as reverse
italic
standout
altfont
nocombine override attributes instead of combining them
NONE no attributes used (used to reset it)

The default color configuration is given below

{
    DiredDimText = { link = {}, bg = "NONE", fg = "505050", gui = "NONE" },
    DiredDirectoryName = { link = {}, bg = "NONE", fg = "9370DB", gui = "NONE" },
    DiredDotfile = { link = {}, bg = "NONE", fg = "626262" },
    DiredFadeText1 = { link = {}, bg = "NONE", fg = "626262", gui = "NONE" },
    DiredFadeText2 = { link = {}, bg = "NONE", fg = "444444", gui = "NONE" },
    DiredSize = { link = { "Normal" }, bg = "NONE", fg = "None", gui = "NONE" },
    DiredUsername = { link = {}, bg = "NONE", fg = "87CEFA", gui = "bold" },
    DiredMonth = { link = { "Normal" }, bg = "NONE", fg = "None", gui = "bold" },
    DiredDay = { link = { "Normal" }, bg = "NONE", fg = "None", gui = "bold" },
    DiredFileName = { link = {}, bg = "NONE", fg = "NONE", gui = "NONE" },
    DiredFileSuid = { link = {}, bg = "ff6666", fg = "000000", gui = "bold" },
    DiredNormal = { link = { "Normal" }, bg = "NONE", fg = "NONE", gui = "NONE" },
    DiredNormalBold = { link = {}, bg = "NONE", fg = "ffffff", gui = "bold" },
    DiredSymbolicLink = { link = {}, bg = "NONE", fg = "33ccff", gui = "bold" },
    DiredBrokenLink = { link = {}, bg = "2e2e1f", fg = "ff1a1a", gui = "bold" },
    DiredSymbolicLinkTarget = { link = {}, bg = "5bd75b", fg = "000000", gui = "bold" },
    DiredBrokenLinkTarget = { link = {}, bg = "2e2e1f", fg = "ff1a1a", gui = "bold" },
    DiredFileExecutable = { link = {}, bg = "NONE", fg = "5bd75b", gui = "bold" },
    DiredMarkedFile = { link = {}, bg = "NONE", fg = "a8b103", gui = "bold" },
    DiredCopyFile = { link = {}, bg = "NONE", fg = "ff8533", gui = "bold" },
    DiredMoveFile = { link = {}, bg = "NONE", fg = "ff3399", gui = "bold" },
}

TODO

  1. Allow changing file permissions.

dired.nvim's People

Contributors

bozkayasalihx avatar dnonov avatar lintaoamons avatar x3ero0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dired.nvim's Issues

Can't be loaded

E5113: Error while calling lua chunk: ...vim/site/pack/packer/start/dired.nvim/lua/dired/init.lua:104: Vim(autocmd):E216: No such group or event: FileExplorer *
stack traceback:
        [C]: in function 'cmd'
        ...vim/site/pack/packer/start/dired.nvim/lua/dired/init.lua:104: in function 'setup'
        

Neovim version: NVIM v0.7.2

    use {
        'X3eRo0/dired.nvim',
        requires = 'MunifTanjim/nui.nvim'
    }
require('dired').setup {
  path_separator = '/',
  show_banner = false,
  show_hidden = true
}

Maybe it is a conflict with nvim-tree?

Toggling sort order fails because M.get_next_sort_order() returns nil.

I've looked into the issue and I think I found a fix, before creating the PR I want to confirm that this isn't an issue only I'm experiencing.
my set up is taken from the README, haven't done anything special to it.
and it works as expected expect when trying to change how the list is sorted.(:DiredToggleSortOrder or pressing ',')
it fails because M.get_next_sort_order() returns nil.

function M.get_next_sort_order()
    local current = vim.g.dired_sort_order
    local sorting_functions = { "name", "date", "dirs" }
    local idx = 0
    for i, str in ipairs(sorting_functions) do
        if str == current then
            table.remove(sorting_functions, i)
            idx = i
        end
    end
    if idx > #sorting_functions then
        idx = 1
    end
    return sorting_functions[idx]
end

E5108: Error executing lua attempt to compare two table values
stack traceback:
[C]: in function 'sort'
.../.local/share/nvim/lazy/dired.nvim/lua/dired/display.lua:91: in function 'get_directory_listing'
.../.local/share/nvim/lazy/dired.nvim/lua/dired/display.lua:144: in function 'display_dired_listing'
.../.local/share/nvim/lazy/dired.nvim/lua/dired/display.lua:25: in function 'render'
...on/.local/share/nvim/lazy/dired.nvim/lua/dired/dired.lua:198: in function 'toggle_sort_order'
[string ":lua"]:1: in main chunk

fails to start

I'm getting this error when executing :Dired or nvim ..

E5108: Error executing lua .../nvim/site/pack/packer/start/dired.nvim/lua/dired/fs.lua:235: attempt to index a nil value
stack traceback:
        .../nvim/site/pack/packer/start/dired.nvim/lua/dired/fs.lua:235: in function 'New'
        ...vim/site/pack/packer/start/dired.nvim/lua/dired/dirs.lua:15: in function 'get_dir_content'
        .../site/pack/packer/start/dired.nvim/lua/dired/display.lua:56: in function 'get_dired_listing'
        .../site/pack/packer/start/dired.nvim/lua/dired/display.lua:79: in function 'display_dired_listing'
        .../site/pack/packer/start/dired.nvim/lua/dired/display.lua:37: in function 'render'
        ...im/site/pack/packer/start/dired.nvim/lua/dired/dired.lua:58: in function 'init_dired'
        ...im/site/pack/packer/start/dired.nvim/lua/dired/dired.lua:82: in function 'open'
        [string ":lua"]:1: in main chunk

Os: MacOs
Nvim version: v0.8.0-dev+595-g95c65a6b2

quit from dired buffer not implemented

I want to express my appreciation for the excellent package, and I'm finding it very useful. However, I've encountered lack of feature when working with Dired mode/buf in the package.

Currently, when I enter a Dired buffer, there is no direct way to exit the buffer without opening or creating a file.

Search in dired buffer

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!

How can I move directories and files

Sys: MacOS Apple Silicon
Terminal: Iterm2
Question:

Hi, I'm wondering how I can Move Marked files/directories in visual or normal mode.

When I select files/directories and I try to move them with MoveMarked or MoveRange I end up only highlighting the dir I'm trying to move it to. I've tried many variants and I can't seem to figure it out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.