Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feature request: :wq #221

Closed
1 task done
arutonee1 opened this issue Nov 12, 2023 · 3 comments
Closed
1 task done

feature request: :wq #221

arutonee1 opened this issue Nov 12, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@arutonee1
Copy link

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

:wq currently behaves like :w. If the command was successful (the user presses [O]k), :wq should close Neovim as well.

Provide background

I genuinely might see myself using oil.nvim as a file manager replacement, and this would save a lot of time for quick operations.

Additional details

No response

@arutonee1 arutonee1 added the enhancement New feature or request label Nov 12, 2023
@stevearc
Copy link
Owner

I added support for this. It's a bit of a hack, but it seems to work well enough. I'm a little concerned that there may be some unintended edge cases, so there's a chance I'll have to tweak this or roll it back.

@collindutter
Copy link

collindutter commented Jan 23, 2024

I'm running into an edge case of this change that causes Neovim to close unexpectedly.

I have the following keymaps:
vim.keymap.set('n', '<leader>w', '<CMD>w<CR>', {})
vim.keymap.set('n', '-', '<CMD>Oil<CR>', {})

To reproduce:

  1. Open Neovim.
  2. Close Neovim with :x.
  3. Open Neovim.
  4. Open Oil with - keymap.
  5. Create a file.
  6. Save the buffer with <leader>w keymap.
  7. Neovim closes.

This happens because commands run through keymaps are not inserted into the history table so the last command is still :x.

Thanks for all the work you do!


EDIT: I found a hack workaround for myself:

vim.keymap.set('n', '<leader>w', function()
  vim.fn.histadd('cmd', 'w')
  pcall(vim.cmd.w)
end, {})

@christianjuth
Copy link

christianjuth commented Feb 1, 2024

I'm using LunarVim and the default <leader>w doesn't play nice with oil. However, I found overwriting the default <leader>w fixes it.

vim.api.nvim_del_keymap('n', '<leader>w')
vim.api.nvim_set_keymap('n', '<leader>w', ':w<CR>', { noremap = true, silent = true })

stevearc added a commit that referenced this issue Mar 12, 2024
The previous mechanism used histget() to get the last command or
expression to detect if the user issued a `:wq` or similar. This had the
issue where if a user issued a `:wq`, started vim again, then entered
oil and saved via some mechanism that is _not_ a command (e.g. a
keymap), we would incorrectly detect that `:wq` and exit after saving.
The new mechanism tracks all keypresses and may end up with false
negatives (e.g. ":wqaff<backspace><backspace>ll"), but those are less
frustrating than false positives.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants