Skip to content

Configuration

TheBlob42 edited this page Nov 9, 2022 · 10 revisions

Vinegar

Add some vim-vinegar flavor:

  • press ~ to jump into your home directory
  • press - to jump to the parent directory
    • keep bouncing up, up, up...
  • press . to pre-populate the element at the end of a : command line
    • e.g. press .!chmod u+x to get :!chmod u+x /path/to/element
local drex = require('drex')
local elements = require('drex.elements')

-- open the home directory
vim.keymap.set('n', '~', '<CMD>Drex ~<CR>', {})
-- open parent DREX buffer and focus current file
vim.keymap.set('n', '-', function()
    local path = vim.fn.expand('%:p')
    if path == '' then
        drex.open_directory_buffer() -- open at cwd
    else
        drex.open_directory_buffer(vim.fn.fnamemodify(path, ':h'))
        elements.focus_element(0, path)
    end
end, {})

require('drex.config').configure {
    keybindings = {
        ['n'] = {
            ['~'] = '<CMD>Drex ~<CR>',
            ['-'] = '<CMD>lua require("drex.elements").open_parent_directory()<CR>',
            ['.'] = function()
                local element = require('drex.utils').get_element(vim.api.nvim_get_current_line())
                local left = vim.api.nvim_replace_termcodes('<left>', true, false, true)
                vim.api.nvim_feedkeys(': ' .. element .. string.rep(left, #element + 1), 'n', true)
            end,
        }
    }
}

Buffer list

By default all DREX buffers are "listed" which means that they will be displayed in the buffer list (see :help 'buflisted' for more information). This allows you to easily navigate between already opened directories

If you don't like this behavior add the following snippet to your configuration:

vim.api.nvim_create_autocmd('FileType', {
    group = vim.api.nvim_create_augroup('DrexNotListed', {}),
    pattern = 'drex',
    command = 'setlocal nobuflisted'
})

Cursor column

The hide_cursor configuration option will hide the cursor in DREX buffers by default via a custom guicursor setting. Maybe your terminal does not support this setting or you like to have the actual cursor as an additional marker for the current line. If you like this but also would like to keep the cursor at column 0 (to prevent it from "jumping around") you can use the following snippet

-- create or get group but don't clear it to not delete autocommands of other buffers
local group = vim.api.nvim_create_augroup('DrexCursor', { clear = false })

-- only clear buflocal autocommands
vim.api.nvim_clear_autocmds({
    group = group,
    buffer = 0,
})

vim.api.nvim_create_autocmd('CursorMoved', {
    group = group,
    buffer = 0,
    command = 'normal! 0'
})

Save this snippet within your personal configuration in ftplugin/drex.lua for it to take effect

As an alternative you could also use the snippet within the on_enter function but that is not recommended as it resets the autocommand on every enter (instead on filetype)

Lualine extension

The plugin comes with a custom extension for the lualine plugin which shows the current path of the DREX buffer and the number of elements in the DREX clipboard in the statusline

lualine

require('lualine').setup {
    extensions = { 'drex' },
    [...]
}

Only DREX buffers for the drawer

Sometimes it can happen that a non-DREX buffer finds its way into the DREX drawer window. This is usually not really helpful as the drawer window is mostly too narrow to work on text files there. To prevent non-DREX buffers from "entering" the drawer window you can use the following autocommand:

vim.api.nvim_create_autocmd('BufEnter', {
    group = vim.api.nvim_create_augroup('DrexDrawerWindow', {}),
    pattern = '*',
    callback = function(args)
        if vim.api.nvim_get_current_win() == require('drex.drawer').get_drawer_window() then
            local is_drex_buffer = function(b)
                local ok, syntax = pcall(vim.api.nvim_buf_get_option, b, 'syntax')
                return ok and syntax == 'drex'
            end
            local prev_buf = vim.fn.bufnr('#')

            if is_drex_buffer(prev_buf) and not is_drex_buffer(args.buf) then
                vim.api.nvim_set_current_buf(prev_buf)
                vim.schedule(function()
                    vim.cmd([['"]]) -- restore former cursor position
                end)
            end
        end
    end
})

This will interfere with the jumplist and the alternate-file

Clone this wiki locally