You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use a keymap, like <Leader>o, to flip the card between the file and the file directory keeping the current file in buffer synced with the file in the oil directory list. Like this:
neovim_oil_nvim_open_and_select_file.mov
Provide background
I'm trying to get comfortable with the idea of the card-flip transition for directory explorer. I was using default Netrw for that, but I couldn't figure out how to highlight the current file in buffer when I flip the card to the directories view.
In projects with lots of directories and files, it is pretty easy to get lost.
Motivated by the concept of "edit your filesystem like a normal Neovim buffer" I'm trying oil.nvim. But, I also could not figure it out how to properly do this.
Current Solution
After some search I end up with the following config:
vim.api.nvim_set_keymap('n', '<leader>o', ':lua open_oil_and_select_current_file()<CR>', { noremap = true, silent = true })
function open_oil_and_select_current_file()
local current_path = vim.fn.expand('%:p:h')
local bufname = vim.fn.expand('%:t')
require('oil').open(current_path)
vim.defer_fn(function()
-- Find and highlight the current buffer's file in netrw
vim.cmd('/' .. bufname .. '$')
end, 50)
end
To flip the card back I use this autocmd:
local augroup = vim.api.nvim_create_augroup -- Create/get autocommand group
local autocmd = vim.api.nvim_create_autocmd -- Create autocommand
augroup('netrw_oil_config', { clear = true })
autocmd('Filetype', {
group = 'netrw_oil_config',
pattern = 'oil',
callback = function()
vim.api.nvim_buf_set_keymap(
0, -- In the current buffer
"n", -- at Normal mode
"<Leader>o", -- Map the <Leader> o keys
"<C-o>", { -- to close buffer without closing the window
noremap = true, -- without recurcively expand it
silent = true -- and without displaing it on command-line window
})
end
})
What is the significance of this feature?
nice to have
Additional details
Is there another way to achieve this I could not find in the docs?
I'm using defer to ensure Oil is opened before search, otherwise I got an error the pattern wasn't found. Can we have a callback for the API method open, so I can ensure the search only happens after the Oil buffer is ready?
Am I missing anything?
The text was updated successfully, but these errors were encountered:
Did you check existing requests?
Describe the feature
I want to use a keymap, like
<Leader>o
, to flip the card between the file and the file directory keeping the current file in buffer synced with the file in the oil directory list. Like this:neovim_oil_nvim_open_and_select_file.mov
Provide background
I'm trying to get comfortable with the idea of the card-flip transition for directory explorer. I was using default Netrw for that, but I couldn't figure out how to highlight the current file in buffer when I flip the card to the directories view.
In projects with lots of directories and files, it is pretty easy to get lost.
Motivated by the concept of "edit your filesystem like a normal Neovim buffer" I'm trying oil.nvim. But, I also could not figure it out how to properly do this.
Current Solution
After some search I end up with the following config:
To flip the card back I use this autocmd:
What is the significance of this feature?
nice to have
Additional details
Is there another way to achieve this I could not find in the docs?
Is it a good candidate for the Receipts section in the Docs?
I'm using defer to ensure Oil is opened before search, otherwise I got an error the pattern wasn't found. Can we have a callback for the API method
open
, so I can ensure the search only happens after the Oil buffer is ready?Am I missing anything?
The text was updated successfully, but these errors were encountered: