kevinhwang91 / rnvimr

Make Ranger running in a floating window to communicate with Neovim via RPC
BSD 3-Clause "New" or "Revised" License
800 stars 17 forks source link

In netrw mode, three quits are required to close vim #127

Closed Nimmidev closed 1 year ago

Nimmidev commented 1 year ago

Ranger

Python

Pynvim

Ueberzug (optional)

RPC

**Describe the bug**  
When ranger is used as a netrw replacement it does not immediately quit on q/`:q`.
The first q/`:q` causes the screen to flash once. The second one will close ranger and the last `:q` is required to close vim.

**To Reproduce using `nvim -u mini.lua`**

Example:
`cat mini.lua`
```lua
-- use your plugin manager, here is `packer`
require("packer").startup(function(use)

        use 'wbthomason/packer.nvim'

        use {
                "kevinhwang91/rnvimr",
                config = function()
                        vim.g.rnvimr_enable_ex = true
                end
        }

end)

Steps to reproduce the behavior:

  1. Install rnvmr
  2. Enable netrw replacement: vim.g.rnvimr_enable_ex = true
  3. Open vim with vim .
  4. Press q or :q (screen flashes once)
  5. Press q or :q again (ranger is closed, empty vim buffer is visible now)
  6. Exit vim :q

Expected behavior
Ranger and vim should close after pressing q or :q once (in netrw replacement mode).

kevinhwang91 commented 1 year ago

Weird, only double :q for me to exit nvim.

Nimmidev commented 1 year ago

Sorry i totally missed your answer 5 days ago. I just migrated my email, seems like i overlooked that one.

Its weird that you only have to quite twice. With the config and steps provided, on two different machines i need three. Also another friend with the same config just confirmed it on his machine as well.

Nevertheless, double :q also seems odd. Doesn't it? If you use ranger as a netrw replacement, you probably expect it to quit immediately after one :q not two. Seems a bit counterproductive to me.

kevinhwang91 commented 1 year ago

Be reproduced in min config, I can't reproduce the issue because I have set up:

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

in my init.lua.

The code is written while I'm using vim-plug whose load order is different than packer.nvim, some of code is out of action. The issue has been fixed now, thanks.

Nimmidev commented 1 year ago

Awesome, can confirm i only need two quits now to close vim. Thank you.

Do you know if there is a way to make vim quit just after one :q? Its totally okay if its not the intended default behavior of rnvimr. It just doesn't feel right to me.

kevinhwang91 commented 1 year ago
vim.api.nvim_create_autocmd('VimEnter', {
    pattern = '*',
    once = true,
    callback = function()
        local name = vim.api.nvim_buf_get_name(0)
        if vim.fn.isdirectory(name) == 1 then
            vim.api.nvim_create_autocmd('FileType', {
                pattern = 'rnvimr',
                once = true,
                callback = function()
                    vim.api.nvim_create_autocmd('WinLeave', {
                        buffer = 0,
                        once = true,
                        callback = function()
                            vim.schedule(function()
                                name = vim.api.nvim_buf_get_name(0)
                                local off = vim.api.nvim_buf_get_offset(0, 1)
                                if name == '' and off <= 0 then
                                    vim.cmd('q')
                                end
                            end)
                        end
                    })
                end
            })
        end
    end
})

look redundant, but work fine.

Nimmidev commented 1 year ago

Works like a charm. tyvm