willthbill / opener.nvim

Workspace / context switcher plugin for neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

opener.nvim

A workspace/context switcher for neovim. It allows you to open directories / folders and reset the neovim instance (like in vscode and other editors). This is especially useful for neovim-GUI's such as neovide, which you may not want to restart.

For quick questions feel free to ask on reddit.

Preview

📦 Installation

Telescope is an optional, but a recommended dependency. I also recommend installing fd, but it is not required.

Packer:

use "willthbill/opener.nvim"

vim-plug:

Plug 'willthbill/opener.nvim'

You may want to pre-load the opener telescope extension.

require('telescope').load_extension("opener")

🚀 Usage

The following vim commands are available.

:Clear " Closes all buffers, tabs and windows, however it does not close unsaved buffers
:Open <directory> " Opens a directory and clears nvim

You can call the telescope extension like this.

:Telescope opener
:Telescope opener hidden=false respect_gitignore=true root_dir="~"

From lua you can call the extension like this.

lua

require('telescope').extensions.opener.opener()
require('telescope').extensions.opener.opener {
    hidden=false,
    respect_gitignore=true,
    root_dir="~",
}

hidden shows hidden files, respect_gitignore respects .gitignore files (--no-ignore-vcs fd flag), and root-dir is the directory to list subdirectories from.

⚙️ Configuration

Hooks

You can call the opener.setup function to configure opener.nvim.

lua

require('opener').setup {
    pre_open = {}
    post_open = {}
}

pre_open and post_open are strings (vim-commands) or functions (lua functions) or tables/lists of strings/functions. lua functions will be given an argument, which is the directory, which will be/was changed to.

All commands/functions in pre_open are called before the cwd (current working directory) is changed by :Open or the Telescope extension.

All commands/functions in post_open are called after the cwd (current working directory) is changed by :Open or the Telescope extension.

Telescope extension default values

When you set up telescope you may specify default values for the arguments for the opener extension.

lua

require('telescope').setup {
    extensions = {
        opener = {
            hidden = false, -- do not show hidden directories
            root_dir = "~", -- search from home directory by default
            respect_gitignore = true, -- respect .gitignore files
        }
    }
}

Keymaps

You may want to map the telescope extension to a keymap.

lua

vim.api.nvim_set_keymap("n", "<leader>o", ":Telescope opener<cr>", { noremap = true, silent = true })

vim script

nnoremap <leader>o :Telescope opener<cr>

⚡ Example setup

The following is an example setup of opener.nvim.

~/.config/nvim/init.lua

... -- packer setup
    use {
        "~/projects/opener.nvim",
        config = function()
            require('telescope').load_extension("opener")
        end
    }
...
require('telescope').setup {
    ...
    extensions = {
        opener = {
            hidden = false, -- do not show hidden directories
            root_dir = "~", -- search from home directory by default
            respect_gitignore = true, -- respect .gitignore files
        }
    }
}
...
require('opener').setup {
    pre_open = function(new_dir)
        print("Yay, opening " .. new_dir .. " in a moment")
    end
    post_open = { "NERDTree", function(new_dir)
        print(new_dir .. " was opened")
    end}
}

About

Workspace / context switcher plugin for neovim


Languages

Language:Lua 94.1%Language:Vim Script 5.9%