Zachary W. Huang

Home Projects Blog Guides Resume

Opening Multiple Buffers with Telescope

May 25, 2025

So, I use a bufferline in my Neovim config since I find it convenient to be able to cycle between different files while coding. I have :bnext and :bprev bound to <leader>. and <leader>, (think of the < and > and pointing left and right), which makes it easy to quickly navigate buffers.

I also use the Telescope (not the Balatro joker) to fuzzy-find files based on their filename. I do this so often I have :Telescope find_files bound to <leader><leader> (plus my <leader> is actually the Space key). However, I realized that there isn’t an easy way to open multiple files in the Telescope pane in different buffers — there is only a binding that puts all marked files in the quickfix list. As of now, the quickfix list isn’t a big part of my workflow (other than occasionally using cdo magic to execute commands in multiple buffers), so this isn’t all that useful to me. However, I found that it’s a pretty common situation in which there are multiple related files I want to open (ex: trying to both interface and implementation files in languages like C++ or OCaml)

To address this, I added a small snippet to my Telescope config.

return {
    "nvim-telescope/telescope.nvim",
    opts = {
        defaults = {
            mappings = {
                -- Open all marked files in different buffers
                i = {
                    ["<C-o>"] = function(prompt_bufnr)
                        -- open all files in quickfix list in new buffers
                        require('telescope.actions').send_selected_to_qflist(prompt_bufnr, " ")
                        vim.cmd('silent cfdo edit')
                    end,
                },
                n = {
                    ["<C-o>"] = function(prompt_bufnr)
                        -- open all files in quickfix list in new buffers
                        require('telescope.actions').send_selected_to_qflist(prompt_bufnr, " ")
                        vim.cmd('silent cfdo edit')
                    end,
                },
            },
        },
    }
}

Now, I can easily fuzzy-find with Telescope, mark multiple files of interest, and then open them all with <C-o>.

github logo linkedin logo

Zachary W. Huang © 2021-2025