Fix netrw - mapping when in a buffer with no name/file
This commit is contained in:
parent
6c0c906cb2
commit
6533a96ba0
@ -10,10 +10,16 @@ end
|
||||
vim.keymap.set('n', '-', function()
|
||||
-- Get the filename before invoking netrw
|
||||
local filename = vim.fn.expand('%:t')
|
||||
local directory = vim.fn.expand('%:hp')
|
||||
|
||||
if directory == '' then
|
||||
directory = vim.fn.getcwd()
|
||||
end
|
||||
|
||||
-- Invoke netrw on the directory containing the current file
|
||||
vim.fn.execute(string.format("edit %s", vim.fn.expand('%:hp')))
|
||||
vim.fn.execute(string.format("edit %s", directory))
|
||||
|
||||
if filename ~= '' then
|
||||
-- In the netrw buffer, move the cursor to the first character of filename
|
||||
local buffer = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(buffer, 0, -1, true)
|
||||
@ -24,4 +30,5 @@ vim.keymap.set('n', '-', function()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user