Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Opening a file without closing Oil #399

Open
1 task done
6H075T2 opened this issue Jun 1, 2024 · 5 comments
Open
1 task done

Opening a file without closing Oil #399

6H075T2 opened this issue Jun 1, 2024 · 5 comments
Labels
enhancement New feature or request P1 May get worked on if I get free time. PRs welcome

Comments

@6H075T2
Copy link

6H075T2 commented Jun 1, 2024

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

I want to open a file in Oil without closing Oil after opening a file in a new buffer. Is there any way to do this?

Provide background

Sometimes I'm working with multiple files and want to open them with Oil and it gets tedious if every time I open a file, I do the process of opening Oil and selecting the file again and again.

What is the significance of this feature?

nice to have

Additional details

Mini.files have similar feature with their go_in function.
Recording 2024-06-01 155042

@6H075T2 6H075T2 added the enhancement New feature or request label Jun 1, 2024
@jakubbortlik
Copy link

Hi @6H075T2, you are probably looking for the select_split, select_vsplit and select_tab functions. See :h actions.select_split. They even have default keybindings (that you can change when setting up the plugin, see :h oil-config):

        ["<C-s>"] = "actions.select_vsplit",
        ["<C-h>"] = "actions.select_split",
        ["<C-t>"] = "actions.select_tab",

@6H075T2
Copy link
Author

6H075T2 commented Jun 14, 2024

Hello @jakubbortlik, I'm fairly new to Neovim's ecosystem and I'm used to editing files per buffer because my monitor is too small to handle multiple splits. I want the same functionality as the GIF above where I can open files in Oil in a new buffer without closing Oil.

@jakubbortlik
Copy link

Oh, I see, I didn't notice that you are opening the new buffers in individual tabs. Well, I'm not used to this kind of workflow, and I'm not sure this is fully supported in oil.nvim. The select action can take an opts table where you can specify, whether the original oil buffer should be closed (see :h oil.select), but it doesn't seem to work for float windows. As a workaround you can use the callback parameter of select and open the oil buffer again. This does not work as nicely as the mini example, since the screen flickers due to closing and reopening the oil buffer, but it's close enough:
If you are using lazy.nvim, you can place this in a oil.lua file somewhere in your config directory:

return {
  'stevearc/oil.nvim',
  opts = {
    float = {
      max_width = 80,
    },
    keymaps = {
      ["<C-t>"] =  '<cmd>lua require("oil").select({close=false, tab=true}, function() require("oil").open_float() end)<cr>',
    },
  },
  config = function(_, opts)
    require("oil").setup(opts)
    vim.keymap.set("n", "-", "<CMD>lua require('oil').open_float()<CR>", { desc = "Open parent directory in floating window" })
  end
}

@6H075T2
Copy link
Author

6H075T2 commented Jun 16, 2024

Thanks for your help @jakubbortlik. I'm hoping the maintainer sees this and find a way to implement it would be a great help.

@stevearc stevearc added the P1 May get worked on if I get free time. PRs welcome label Jun 19, 2024
@windowsrefund
Copy link

Yea, this doesn't appear to work

    ["<S-CR>"] = { "actions.select", opts = { close = false }, desc = "Open entry under the cursor without closing Oil" },

I see the work-around mentioned above involving the 2 step approach (select, open_float()) but can foresee edge cases like that follow-up open_float opening cwd rather than the path where the user was when selecting the file. That said, it would be much cleaner to know close = false was honored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 May get worked on if I get free time. PRs welcome
Projects
None yet
Development

No branches or pull requests

4 participants