mirror of
https://github.com/neovim/neovim.git
synced 2026-04-20 06:20:53 +00:00
feat(defaults): :Open without args opens current file #38776
Problem: Running `:Open` on an open buffer does not run `vim.ui.open()` on that file, requiring the user to type `:Open %`. This is inconsistent with most other vim commands which accept files, which default to the current buffer's file. Solution: Default to the current file when `:Open` is used without arguments.
This commit is contained in:
@@ -139,7 +139,7 @@ CHANGED FEATURES *news-changed*
|
||||
|
||||
These existing features changed their behavior.
|
||||
|
||||
• todo
|
||||
• |:Open| with no arguments uses the current file.
|
||||
|
||||
==============================================================================
|
||||
REMOVED FEATURES *news-removed*
|
||||
|
||||
@@ -34,10 +34,17 @@ do
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command('Open', function(cmd)
|
||||
vim.ui.open(assert(cmd.fargs[1]))
|
||||
if #cmd.fargs == 0 then
|
||||
local current_file = vim.fn.expand('%')
|
||||
if current_file ~= '' then
|
||||
vim.ui.open(current_file)
|
||||
end
|
||||
else
|
||||
vim.ui.open(cmd.fargs[1])
|
||||
end
|
||||
end, {
|
||||
desc = 'Open file with system default handler. See :help vim.ui.open()',
|
||||
nargs = 1,
|
||||
nargs = '?',
|
||||
complete = 'file',
|
||||
})
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user