Browse Source

Merge branch 'master' of http://git.nixlab.in/chodak166/dotfiles into trb

trb
chodylal 1 month ago
parent
commit
6458e17100
  1. 14
      .config/nvim/lua/config/keymaps.lua
  2. 27
      .config/nvim/lua/config/terminal.lua
  3. 2
      .config/nvim/lua/plugins/terminal.lua

14
.config/nvim/lua/config/keymaps.lua

@ -1,3 +1,17 @@
-- Keymaps are automatically loaded on the VeryLazy event -- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua -- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here -- Add any additional keymaps here
-- Override LazyVim's <C-/> / <C-_>: count 99 opens the floating terminal,
-- everything else stays native (bottom terminal at project root).
-- Both keys are mapped because terminals differ in which code Ctrl+/ sends.
local function term_open()
if vim.v.count == 99 then
require("config.terminal").open_float()
else
Snacks.terminal.focus(nil, { cwd = LazyVim.root() })
end
end
vim.keymap.set({ "n", "t" }, "<C-/>", term_open, { desc = "Terminal (Root Dir) | 99<C-/> = float" })
vim.keymap.set({ "n", "t" }, "<C-_>", term_open, { desc = "Terminal (Root Dir) | 99<C-/> = float" })

27
.config/nvim/lua/config/terminal.lua

@ -5,20 +5,19 @@
-- count, e.g. 2<C-/> opens a *separate* terminal #2) -- count, e.g. 2<C-/> opens a *separate* terminal #2)
-- <leader>fT terminal in the current working directory -- <leader>fT terminal in the current working directory
-- --
-- This module adds: -- This module adds (actual key bindings are declared in lua/plugins/terminal.lua):
-- <Tab> open/focus a *dedicated* floating terminal (close it with <C-/>) -- open_float() open/focus a *dedicated* floating terminal (close it with <C-/>)
-- <leader>ft a picker that lists every live terminal so any contextual -- picker() list every live terminal so any contextual terminal can be
-- terminal can be focused or restored even after its window was -- focused or restored even after its window was closed/hidden.
-- closed/hidden.
local M = {} local M = {}
-- The <Tab> floating terminal. Tracked as an upvalue so <Tab> always re-focuses -- The floating terminal. Tracked as an upvalue so the same key always re-focuses
-- the *same* float regardless of which directory the editor is in. -- the *same* float regardless of which directory the editor is in.
---@type snacks.win? ---@type snacks.win?
local float local float
--- Open or focus the <Tab> floating terminal, or hide it if already focused. --- Open or focus the floating terminal, or hide it if already focused.
-- NOTE: currently unused; <Tab> calls open_float() instead so shell -- NOTE: currently unused; the binding calls open_float() instead so shell
-- tab-completion keeps working while the terminal is open. Kept around for a -- tab-completion keeps working while the terminal is open. Kept around for a
-- future explicit open/close toggle. -- future explicit open/close toggle.
function M.toggle_float() function M.toggle_float()
@ -35,17 +34,17 @@ function M.toggle_float()
-- First open: a high fixed count guarantees this terminal never collides with -- First open: a high fixed count guarantees this terminal never collides with
-- the count-keyed bottom terminals (1, 2, 3 ...), so it is always the *same* -- the count-keyed bottom terminals (1, 2, 3 ...), so it is always the *same*
-- float for <Tab> no matter the context. -- float for <C-Tab> no matter the context.
float = Snacks.terminal(nil, { float = Snacks.terminal(nil, {
count = 99, count = 99,
win = { position = "float", border = "rounded" }, win = { position = "float", border = "rounded" },
}) })
-- Close it with a single keystroke from inside the shell: <Tab> hides the -- Close it with a single keystroke from inside the shell: hides the
-- window (buffer-local, so it only affects this floating terminal and never -- window (buffer-local, so it only affects this floating terminal and never
-- the bottom split, where shell tab-completion must keep working). -- the bottom split, where shell tab-completion must keep working).
if float and float.buf then if float and float.buf then
vim.keymap.set("t", "<Tab>", function() vim.keymap.set("t", "<leader>tt", function()
if float and float:win_valid() then if float and float:win_valid() then
float:hide() float:hide()
end end
@ -53,8 +52,8 @@ function M.toggle_float()
end end
end end
--- Open or focus the <Tab> floating terminal. This never hides the window, so --- Open or focus the floating terminal. This never hides the window, so
--- once the float is open <Tab> falls through to the shell and stays available --- once the float is open the key falls through to the shell and stays available
--- for tab-completion. Close the floating terminal with <C-/> while it is --- for tab-completion. Close the floating terminal with <C-/> while it is
--- visible (handled by Snacks' native terminal keymap). --- visible (handled by Snacks' native terminal keymap).
function M.open_float() function M.open_float()
@ -71,7 +70,7 @@ function M.open_float()
-- First open: a high fixed count guarantees this terminal never collides with -- First open: a high fixed count guarantees this terminal never collides with
-- the count-keyed bottom terminals (1, 2, 3 ...), so it is always the *same* -- the count-keyed bottom terminals (1, 2, 3 ...), so it is always the *same*
-- float for <Tab> no matter the context. -- float for <C-Tab> no matter the context.
float = Snacks.terminal(nil, { float = Snacks.terminal(nil, {
count = 99, count = 99,
win = { position = "float", border = "rounded" }, win = { position = "float", border = "rounded" },

2
.config/nvim/lua/plugins/terminal.lua

@ -5,7 +5,7 @@ return {
"folke/snacks.nvim", "folke/snacks.nvim",
keys = { keys = {
{ {
"<Tab>", "<leader>tt",
function() function()
require("config.terminal").open_float() require("config.terminal").open_float()
end, end,

Loading…
Cancel
Save