Skip to content

ingur/floatty.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

floatty.nvim

floatty

Neovim Version Lua License

A tiny (<200 LOC) but highly customizable floating terminal plugin. Inspired by toggleterm.nvim but focused on simplicity.

Features

  • Easily toggle floating terminals and custom windows using .toggle(opts).
  • Customize window size, positioning, and appearance.
  • Support for custom terminal commands (e.g lazygit), working directories, and window options.

Requirements

  • Neovim 0.11+

Installation

Install with your favorite package manager. For example, in lazy.nvim:

{ "ingur/floatty.nvim" }

Quickstart

-- initialize config
local term = require("floatty").setup({})

-- set toggle keybinds (supports v:count by default!)
vim.keymap.set('n', '<C-t>', function() term.toggle() end)
vim.keymap.set('t', '<C-t>', function() term.toggle() end)

Tip

See more config examples below

Defaults

-- NOTE: all options can be functions to be evaluated
local defaults = {
    file = nil,                -- File to open (if any)
    cmd = vim.o.shell,         -- Terminal command to run
    cwd = vim.fn.getcwd,       -- Working directory of the command
    id = function() return vim.v.count end, -- Identifier for the float
    start_in_insert = true,    -- Start in insert mode
    focus = true,              -- Focus the window after opening
    window = {
        row = nil,               -- Supports percentages (<=1) and absolute sizes (>1)
        col = nil,               -- Supports percentages (<=1) and absolute sizes (>1)
        width = 0.8,             -- Supports percentages (<=1) and absolute sizes (>1)
        height = 0.8,            -- Supports percentages (<=1) and absolute sizes (>1)
        h_align = "center",      -- "left", "center", "right" (used when col is nil)
        v_align = "center",      -- "top", "center", "bottom" (used when row is nil)
        border = "rounded",      -- Border style
        zindex = 50,             -- Z-index of the float
        title = "",              -- window title
        title_pos = "center",    -- "left", "center", "right"
        -- see :h nvim_open_win() for more config options
    },
    wo = {                     -- Window-local options
        cursorcolumn = false,
        cursorline = false,
        cursorlineopt = "both",
        fillchars = "eob: ,lastline:…",
        list = false,
        listchars = "extends:…,tab:  ",
        number = false,
        relativenumber = false,
        signcolumn = "no",
        spell = false,
        winbar = "",
        statuscolumn = "",
        wrap = false,
        sidescrolloff = 0,
        -- other window options are also supported
    },
}

Config examples

Bottom-aligned Terminal

local term = require("floatty").setup({
    window = {
        row = function() return vim.o.lines - 11 end,
        width = 1.0,
        height = 8,
    },
})

vim.keymap.set('n', '<C-t>', function() term.toggle() end)
vim.keymap.set('t', '<C-t>', function() term.toggle() end)

Lazygit float

local lazygit = require("floatty").setup({
    cmd = "lazygit",
    id = vim.fn.getcwd, -- Use the current working directory as the float's ID
})

vim.keymap.set('n', '<C-g>', function() lazygit.toggle() end)
vim.keymap.set('t', '<C-g>', function() lazygit.toggle() end)

Toggling Between Horizontal and Vertical Layouts

local term = require("floatty").setup()
local layout = "horizontal"

term.toggle_layout = function()
    layout = layout == "horizontal" and "vertical" or "horizontal"
    if layout == "horizontal" then
        term.window = {
            row = function() return vim.o.lines - 11 end,
            width = 1.0,
            height = 8,
            h_align = "center",
        }
    else
        term.window = {
            row = nil,
            height = function() return vim.o.lines - 3 end,
            width = 0.25,
            h_align = "right",
            v_align = "top",
        }
    end
end

vim.keymap.set('n', '<leader>tt', term.toggle_layout)

About

A tiny (<200 LOC) but highly customizable floating terminal manager.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages