Dev-Addict/FloatingFile.nvim

github github
file-explorer
stars 2
issues 1
subscribers 0
forks 1
CREATED

UPDATED


FloatingFile.nvim

Open any readable file in a centered Neovim floating window.

FloatingFile.nvim is a small, dependency-free plugin for quickly peeking at a file without replacing your current buffer. It reads the target file into a temporary, read-only scratch buffer, applies Neovim's filetype detection, and closes cleanly with a command or configurable keys.

Requirements

  • Neovim 0.9 or newer.

Installation

Install with your preferred Neovim plugin manager.

lazy.nvim

{
  "Dev-Addict/FloatingFile.nvim",
}

With custom options:

{
  "Dev-Addict/FloatingFile.nvim",
  opts = {
    width = 0.8,
    height = 0.8,
    border = "rounded",
    wrap = false,
  },
  config = function(_, opts)
    require("floating_file").setup(opts)
  end,
}

packer.nvim

use("Dev-Addict/FloatingFile.nvim")

vim-plug

Plug 'Dev-Addict/FloatingFile.nvim'

The plugin auto-registers its commands when loaded. Call require("floating_file").setup() only when you want to override the defaults.

Usage

Open a file:

:FloatingFile path/to/file

Run :FloatingFile with no path to choose a file using vim.ui.input. The current buffer path is used as the default when one exists.

Close the floating window with q, <Esc>, or:

:FloatingFileClose

Configuration

FloatingFile.nvim works without configuration. To customize the floating window, call setup() with any of the available options:

require("floating_file").setup({
  width = 0.8,
  height = 0.8,
  border = "rounded",
  title_pos = "center",
  focus = true,
  wrap = false,
  close_keys = { "q", "<Esc>" },
})

Options

Option Type Default Description
width number 0.8 Floating window width. Values between 0 and 1 are treated as a percentage of the editor width.
height number 0.8 Floating window height. Values between 0 and 1 are treated as a percentage of the editor height.
border string or table "rounded" Border style passed to nvim_open_win().
title_pos string "center" Floating window title position.
focus boolean true Focus the floating window after opening it.
wrap boolean false Enable line wrapping in the floating window.
close_keys string[] { "q", "<Esc>" } Normal-mode keys mapped in the floating buffer to close the window.

Lua API

local floating_file = require("floating_file")

floating_file.open("path/to/file")
floating_file.close()
floating_file.prompt()

open(path, opts) accepts the same options as setup() for one-off overrides.