Big cleanup for a big commit.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[general]
|
||||
|
||||
[font]
|
||||
size = 12
|
||||
size = 12.4
|
||||
offset = { x = 0, y = 3 }
|
||||
normal = { family = "JetBrainsMono Nerd Font", style = "Regular" }
|
||||
|
||||
@@ -14,39 +14,26 @@ padding.y = 10
|
||||
style.shape = "Beam"
|
||||
style.blinking = "Always"
|
||||
|
||||
# Kanagawa Wave Alacritty Colors
|
||||
[colors.primary]
|
||||
background = '#101010'
|
||||
foreground = '#dcd7ba'
|
||||
foreground = '#ebdbb2'
|
||||
|
||||
[colors.normal]
|
||||
black = '#090618'
|
||||
red = '#c34043'
|
||||
green = '#76946a'
|
||||
yellow = '#c0a36e'
|
||||
blue = '#7e9cd8'
|
||||
magenta = '#957fb8'
|
||||
cyan = '#6a9589'
|
||||
white = '#c8c093'
|
||||
black = '#282828'
|
||||
red = '#cc241d'
|
||||
green = '#98971a'
|
||||
yellow = '#d79921'
|
||||
blue = '#458588'
|
||||
magenta = '#b16286'
|
||||
cyan = '#689d6a'
|
||||
white = '#a89984'
|
||||
|
||||
[colors.bright]
|
||||
black = '#727169'
|
||||
red = '#e82424'
|
||||
green = '#98bb6c'
|
||||
yellow = '#e6c384'
|
||||
blue = '#7fb4ca'
|
||||
magenta = '#938aa9'
|
||||
cyan = '#7aa89f'
|
||||
white = '#dcd7ba'
|
||||
|
||||
[colors.selection]
|
||||
background = '#2d4f67'
|
||||
foreground = '#c8c093'
|
||||
|
||||
[[colors.indexed_colors]]
|
||||
index = 16
|
||||
color = '#ffa066'
|
||||
|
||||
[[colors.indexed_colors]]
|
||||
index = 17
|
||||
color = '#ff5d62'
|
||||
black = '#928374'
|
||||
red = '#fb4934'
|
||||
green = '#b8bb26'
|
||||
yellow = '#fabd2f'
|
||||
blue = '#83a598'
|
||||
magenta = '#d3869b'
|
||||
cyan = '#8ec07c'
|
||||
white = '#ebdbb2'
|
||||
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
# ── Core ─────────────────────────────────────────────────────────────────────
|
||||
set shell bash
|
||||
set shellopts '-eu'
|
||||
set ifs "\n"
|
||||
set scrolloff 8
|
||||
set icons true
|
||||
set period 1
|
||||
set hiddenfiles ".*:*.aux:*.log:*.bbl:*.bcf:*.blg:*.run.xml"
|
||||
set cursorpreviewfmt "\033[7m"
|
||||
|
||||
# ── UI ───────────────────────────────────────────────────────────────────────
|
||||
set drawbox true
|
||||
set ratios 1:2:3
|
||||
set info size:time
|
||||
set sortby natural
|
||||
set dirfirst true
|
||||
|
||||
# ── Preview ──────────────────────────────────────────────────────────────────
|
||||
set previewer ~/.local/bin/lfpreview
|
||||
set cleaner ~/.local/bin/lfcleaner
|
||||
|
||||
# ── Keybindings ──────────────────────────────────────────────────────────────
|
||||
|
||||
# unmap defaults we're replacing
|
||||
map m
|
||||
map d
|
||||
map e
|
||||
map f
|
||||
|
||||
# navigation (vim)
|
||||
map h updir
|
||||
map l open
|
||||
map j down
|
||||
map k up
|
||||
map g top
|
||||
map G bottom
|
||||
map <c-d> half-down
|
||||
map <c-u> half-up
|
||||
|
||||
# enter key — writes selection path and quits (for tmux-lf-helix script)
|
||||
map <enter> select-and-quit
|
||||
|
||||
# go-to shortcuts
|
||||
map gh cd ~
|
||||
map gc cd ~/.config
|
||||
map gd cd ~/Downloads
|
||||
map gb cd ~/bin
|
||||
|
||||
# file operations
|
||||
map dd cut
|
||||
map dD delete
|
||||
map yy copy
|
||||
map p paste
|
||||
map r rename
|
||||
map R bulk-rename
|
||||
|
||||
map . set hidden!
|
||||
map <space> toggle
|
||||
|
||||
# new file/dir
|
||||
map mf push %touch<space>
|
||||
map md push %mkdir<space>-p<space>
|
||||
|
||||
cmd extract ${{
|
||||
lfextract "$f"
|
||||
}}
|
||||
map z extract
|
||||
|
||||
# ── Commands ─────────────────────────────────────────────────────────────────
|
||||
|
||||
cmd select-and-quit &{{
|
||||
if [ -n "$fs" ]; then
|
||||
# if files are toggled/selected use those
|
||||
echo "$fs" > "$lf_selection_path_file"
|
||||
else
|
||||
# otherwise use the hovered file
|
||||
echo "$f" > "$lf_selection_path_file"
|
||||
fi
|
||||
lf -remote "send $id quit"
|
||||
}}
|
||||
|
||||
cmd bulk-rename ${{
|
||||
old=$(mktemp)
|
||||
new=$(mktemp)
|
||||
[ -n "$fs" ] && fs=$(ls)
|
||||
printf '%s\n' "$fs" > "$old"
|
||||
printf '%s\n' "$fs" > "$new"
|
||||
$EDITOR "$new"
|
||||
[ "$(wc -l < "$new")" -ne "$(wc -l < "$old")" ] && exit
|
||||
paste "$old" "$new" | while IFS= read -r names; do
|
||||
src=$(printf '%s' "$names" | cut -f1)
|
||||
dst=$(printf '%s' "$names" | cut -f2)
|
||||
[ "$src" = "$dst" ] && continue
|
||||
mv -- "$src" "$dst"
|
||||
done
|
||||
rm "$old" "$new"
|
||||
lf -remote "send $id unselect"
|
||||
}}
|
||||
|
||||
cmd open ${{
|
||||
case $(file --mime-type -b "$f") in
|
||||
text/*|application/json|application/toml|application/yaml)
|
||||
$EDITOR "$f" ;;
|
||||
*)
|
||||
xdg-open "$f" >/dev/null 2>&1 & ;;
|
||||
esac
|
||||
}}
|
||||
+6
-31
@@ -1,6 +1,7 @@
|
||||
require("vim._core.ui2").enable({})
|
||||
map = vim.keymap.set
|
||||
vim.o.termguicolors = true
|
||||
vim.o.showmode = false
|
||||
vim.o.nu = true
|
||||
vim.o.swapfile = false
|
||||
vim.o.winborder = "single"
|
||||
@@ -27,6 +28,7 @@ vim.o.completeopt = "menu,menuone,noselect,popup,fuzzy"
|
||||
vim.o.undofile = true
|
||||
vim.o.undodir = vim.fn.stdpath("state") .. "/undo"
|
||||
vim.o.errorformat = "%f(%l:%c) %m,%-G%.%#"
|
||||
vim.cmd.colorscheme('retrobox')
|
||||
-- -----------------------------
|
||||
-- @BINDS
|
||||
-- -----------------------------
|
||||
@@ -50,42 +52,15 @@ map("i", "<C-h>", vim.lsp.buf.signature_help)
|
||||
-- -----------------------------
|
||||
vim.pack.add({
|
||||
{ src = 'https://github.com/ibhagwan/fzf-lua' },
|
||||
{ src = "https://github.com/saghen/blink.lib" },
|
||||
{ src = "https://github.com/Saghen/blink.cmp" },
|
||||
{ src = 'https://github.com/neovim/nvim-lspconfig' },
|
||||
{ src = 'https://github.com/echasnovski/mini.nvim' },
|
||||
{ src = 'https://github.com/nvim-tree/nvim-tree.lua' },
|
||||
{ src = 'https://github.com/romus204/tree-sitter-manager.nvim' },
|
||||
{ src = 'https://github.com/lukas-reineke/indent-blankline.nvim' },
|
||||
{ src = 'https://github.com/rebelot/kanagawa.nvim' },
|
||||
{ src = 'https://github.com/xiyaowong/transparent.nvim' },
|
||||
{ src = "https://github.com/nvim-tree/nvim-tree.lua" },
|
||||
})
|
||||
|
||||
require("terminal")
|
||||
require("mini.completion").setup()
|
||||
require('mini.statusline').setup()
|
||||
require("mini.surround").setup()
|
||||
require("tree-sitter-manager").setup()
|
||||
require("ibl").setup({
|
||||
indent = { char = "│" },
|
||||
scope = { show_start = false, show_end = false },
|
||||
})
|
||||
vim.cmd.colorscheme('kanagawa')
|
||||
vim.api.nvim_set_hl(0, "WinSeparator", { fg = "#54546D" })
|
||||
|
||||
-- Lsp specific, uses nvim-lspconfigs with the below
|
||||
vim.lsp.enable({ "gopls", "ols" })
|
||||
map("n", "gd", ":lua vim.lsp.buf.definition()<CR>")
|
||||
map("n", "gr", ":lua vim.lsp.buf.rename()<CR>")
|
||||
map("n", "ga", ":lua vim.lsp.buf.code_action()<CR>")
|
||||
|
||||
require("fzf-lua").setup({})
|
||||
map("n", "<C-p>", ":FzfLua files<CR>")
|
||||
map("n", "<C-m>", ":FzfLua buffers<CR>")
|
||||
map("n", "<C-i>", ":FzfLua diagnostics_workspace<CR>")
|
||||
map("n", "<C-f>", ":FzfLua live_grep<CR>")
|
||||
map("n", "<C-b>", ":FzfLua grep_curbuf<CR>")
|
||||
|
||||
require("nvim-tree").setup()
|
||||
map("n", "<C-e>", ":NvimTreeToggle<CR>")
|
||||
require("plugins")()
|
||||
-- -----------------------------
|
||||
-- @AUTOCMDS
|
||||
-- -----------------------------
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
local map = vim.keymap.set
|
||||
|
||||
local blink = require("blink.cmp")
|
||||
|
||||
blink.setup({
|
||||
keymap = {
|
||||
["<Tab>"] = {
|
||||
"select_next",
|
||||
"fallback",
|
||||
},
|
||||
|
||||
["<S-Tab>"] = {
|
||||
"select_prev",
|
||||
"fallback",
|
||||
},
|
||||
|
||||
["<C-n>"] = {
|
||||
"select_next",
|
||||
"fallback",
|
||||
},
|
||||
|
||||
["<C-p>"] = {
|
||||
"select_prev",
|
||||
"fallback",
|
||||
},
|
||||
|
||||
["<CR>"] = {
|
||||
"accept",
|
||||
"fallback",
|
||||
},
|
||||
|
||||
["<C-Space>"] = {
|
||||
"show",
|
||||
"show_documentation",
|
||||
"hide_documentation",
|
||||
},
|
||||
|
||||
["<Esc>"] = {
|
||||
"hide",
|
||||
"fallback",
|
||||
},
|
||||
},
|
||||
|
||||
appearance = {
|
||||
nerd_font_variant = "normal",
|
||||
},
|
||||
|
||||
completion = {
|
||||
menu = {
|
||||
border = "single",
|
||||
},
|
||||
|
||||
documentation = {
|
||||
auto_show = true,
|
||||
auto_show_delay_ms = 200,
|
||||
|
||||
window = {
|
||||
border = "single",
|
||||
},
|
||||
},
|
||||
|
||||
ghost_text = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
|
||||
signature = {
|
||||
enabled = true,
|
||||
},
|
||||
|
||||
sources = {
|
||||
default = {
|
||||
"lsp",
|
||||
"path",
|
||||
"buffer",
|
||||
},
|
||||
},
|
||||
|
||||
fuzzy = { implementation = "lua", },
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,35 @@
|
||||
local M = {}
|
||||
|
||||
local function build(args)
|
||||
if vim.fn.filereadable("build.sh") == 0 then
|
||||
vim.notify("No build.sh found in current directory.", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd("wall")
|
||||
|
||||
local command = "./build.sh"
|
||||
|
||||
if #args > 0 then
|
||||
command = command .. " " .. table.concat(args, " ")
|
||||
end
|
||||
|
||||
require("terminal").send("clear && " .. command)
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
vim.api.nvim_create_user_command(
|
||||
"Build",
|
||||
function(opts) build(opts.fargs) end,
|
||||
{
|
||||
nargs = "*",
|
||||
desc = "Run project build.sh",
|
||||
}
|
||||
)
|
||||
|
||||
local map = vim.keymap.set
|
||||
map("n", "<C-Space>", function() build({}) end, { desc = "Build project", })
|
||||
map("t", "<C-Space>", function() build({}) end, { desc = "Build project", })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,49 @@
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
local map = vim.keymap.set
|
||||
|
||||
require("nvim-tree").setup({
|
||||
view = {
|
||||
width = 35,
|
||||
side = "left",
|
||||
},
|
||||
renderer = {
|
||||
icons = {
|
||||
show = {
|
||||
file = false,
|
||||
folder = false,
|
||||
folder_arrow = false,
|
||||
git = false,
|
||||
diagnostics = false,
|
||||
modified = false,
|
||||
bookmarks = false,
|
||||
},
|
||||
},
|
||||
|
||||
},
|
||||
filters = {
|
||||
dotfiles = false,
|
||||
},
|
||||
git = {
|
||||
enable = false,
|
||||
},
|
||||
diagnostics = {
|
||||
enable = false,
|
||||
},
|
||||
update_focused_file = {
|
||||
enable = true,
|
||||
},
|
||||
|
||||
on_attach = function(bufnr)
|
||||
local api = require("nvim-tree.api")
|
||||
api.config.mappings.default_on_attach(bufnr)
|
||||
vim.keymap.del("n", "<C-e>", { buffer = bufnr })
|
||||
vim.opt_local.statusline = " "
|
||||
end,
|
||||
})
|
||||
|
||||
map("n", "<C-e>", "<Cmd>NvimTreeToggle<CR>", { desc = "Toggle file tree", })
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,15 @@
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
local map = vim.keymap.set
|
||||
|
||||
require("fzf-lua").setup({})
|
||||
|
||||
map("n", "<C-p>", "<Cmd>FzfLua files<CR>")
|
||||
map("n", "<C-m>", "<Cmd>FzfLua buffers<CR>")
|
||||
map("n", "<C-i>", "<Cmd>FzfLua diagnostics_workspace<CR>")
|
||||
map("n", "<C-f>", "<Cmd>FzfLua live_grep<CR>")
|
||||
map("n", "<C-b>", "<Cmd>FzfLua grep_curbuf<CR>")
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,16 @@
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
require("ibl").setup({
|
||||
indent = {
|
||||
char = "│",
|
||||
},
|
||||
|
||||
scope = {
|
||||
show_start = false,
|
||||
show_end = false,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,39 @@
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
local map = vim.keymap.set
|
||||
|
||||
local capabilities = require("blink.cmp").get_lsp_capabilities()
|
||||
|
||||
vim.lsp.config("gopls", {
|
||||
capabilities = capabilities,
|
||||
})
|
||||
|
||||
vim.lsp.config("ols", {
|
||||
capabilities = capabilities,
|
||||
})
|
||||
|
||||
vim.lsp.enable({
|
||||
"gopls",
|
||||
"ols",
|
||||
})
|
||||
|
||||
map("n", "gd", vim.lsp.buf.definition)
|
||||
map("n", "gD", vim.lsp.buf.declaration)
|
||||
map("n", "gi", vim.lsp.buf.implementation)
|
||||
map("n", "gr", vim.lsp.buf.references)
|
||||
|
||||
map("n", "K", vim.lsp.buf.hover)
|
||||
map("i", "<C-h>", vim.lsp.buf.signature_help)
|
||||
|
||||
map("n", "<leader>rn", vim.lsp.buf.rename)
|
||||
map("n", "<leader>ca", vim.lsp.buf.code_action)
|
||||
|
||||
map("n", "[d", vim.diagnostic.goto_prev)
|
||||
map("n", "]d", vim.diagnostic.goto_next)
|
||||
|
||||
map("n", "<leader>d", vim.diagnostic.open_float)
|
||||
map("n", "<leader>q", vim.diagnostic.setloclist)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,15 @@
|
||||
return function()
|
||||
require("fuzzyfinder").setup()
|
||||
require("treesitter").setup()
|
||||
require("indent").setup()
|
||||
require("autocomplete").setup()
|
||||
require("lsp").setup()
|
||||
require("terminal").setup()
|
||||
require("filetree").setup()
|
||||
require("build").setup()
|
||||
require("statusbar").setup({
|
||||
bg = "#111111",
|
||||
fg = "#ffffff",
|
||||
separator = " │ ",
|
||||
})
|
||||
end
|
||||
@@ -0,0 +1,188 @@
|
||||
local M = {}
|
||||
|
||||
local config = {
|
||||
bg = "#202020",
|
||||
fg = "#ffffff",
|
||||
separator = " │ ",
|
||||
}
|
||||
|
||||
local mode_names = {
|
||||
["n"] = "NORMAL",
|
||||
["no"] = "NORMAL",
|
||||
["nov"] = "NORMAL",
|
||||
["noV"] = "NORMAL",
|
||||
["no\22"] = "NORMAL",
|
||||
["niI"] = "NORMAL",
|
||||
["niR"] = "NORMAL",
|
||||
["niV"] = "NORMAL",
|
||||
|
||||
["i"] = "INSERT",
|
||||
["ic"] = "INSERT",
|
||||
["ix"] = "INSERT",
|
||||
|
||||
["v"] = "VISUAL",
|
||||
["V"] = "V-LINE",
|
||||
["\22"] = "V-BLOCK",
|
||||
|
||||
["s"] = "SELECT",
|
||||
["S"] = "S-LINE",
|
||||
["\19"] = "S-BLOCK",
|
||||
|
||||
["R"] = "REPLACE",
|
||||
["Rc"] = "REPLACE",
|
||||
["Rv"] = "V-REPLACE",
|
||||
|
||||
["c"] = "COMMAND",
|
||||
["cv"] = "COMMAND",
|
||||
["ce"] = "COMMAND",
|
||||
|
||||
["r"] = "PROMPT",
|
||||
["rm"] = "MORE",
|
||||
["r?"] = "CONFIRM",
|
||||
|
||||
["!"] = "SHELL",
|
||||
["t"] = "TERMINAL",
|
||||
}
|
||||
|
||||
local function mode()
|
||||
return mode_names[vim.fn.mode()] or "UNKNOWN"
|
||||
end
|
||||
|
||||
local function filename()
|
||||
local name = vim.fn.expand("%:t")
|
||||
|
||||
if name == "" then
|
||||
return "[No Name]"
|
||||
end
|
||||
|
||||
return name
|
||||
end
|
||||
|
||||
local function git_branch()
|
||||
local branch = vim.b.gitsigns_head
|
||||
|
||||
if branch and branch ~= "" then
|
||||
return " " .. branch
|
||||
end
|
||||
|
||||
return ""
|
||||
end
|
||||
|
||||
local function filetype()
|
||||
if vim.bo.filetype == "" then
|
||||
return "text"
|
||||
end
|
||||
|
||||
return vim.bo.filetype
|
||||
end
|
||||
|
||||
local function active_lsp()
|
||||
local clients = vim.lsp.get_clients({
|
||||
bufnr = 0,
|
||||
})
|
||||
|
||||
if #clients == 0 then
|
||||
return "-"
|
||||
end
|
||||
|
||||
local names = {}
|
||||
|
||||
for _, client in ipairs(clients) do
|
||||
table.insert(names, client.name)
|
||||
end
|
||||
|
||||
return table.concat(names, ",")
|
||||
end
|
||||
|
||||
local function diagnostics()
|
||||
local errors = #vim.diagnostic.get(0, {
|
||||
severity = vim.diagnostic.severity.ERROR,
|
||||
})
|
||||
|
||||
if errors > 0 then
|
||||
return "%#StatusError#●%*"
|
||||
end
|
||||
|
||||
local warnings = #vim.diagnostic.get(0, {
|
||||
severity = vim.diagnostic.severity.WARN,
|
||||
})
|
||||
|
||||
if warnings > 0 then
|
||||
return "%#StatusWarn#●%*"
|
||||
end
|
||||
|
||||
return "%#StatusNormal#●%*"
|
||||
end
|
||||
|
||||
local function position()
|
||||
return string.format("%d:%d", vim.fn.line("."), vim.fn.col("."))
|
||||
end
|
||||
|
||||
local function build()
|
||||
local left = table.concat({
|
||||
" ",
|
||||
mode(),
|
||||
config.separator,
|
||||
diagnostics(),
|
||||
config.separator,
|
||||
filename(),
|
||||
})
|
||||
|
||||
local right = {}
|
||||
|
||||
local branch = git_branch()
|
||||
|
||||
if branch ~= "" then
|
||||
table.insert(right, branch)
|
||||
end
|
||||
|
||||
table.insert(right, filetype())
|
||||
table.insert(right, active_lsp())
|
||||
table.insert(right, position())
|
||||
|
||||
return left
|
||||
.. "%="
|
||||
.. " "
|
||||
.. table.concat(right, config.separator)
|
||||
.. " "
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
config = vim.tbl_extend("force", config, opts or {})
|
||||
|
||||
vim.api.nvim_set_hl(0, "StatusLine", {
|
||||
fg = config.fg,
|
||||
bg = config.bg,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_hl(0, "StatusLineNC", {
|
||||
fg = config.fg,
|
||||
bg = config.bg,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_hl(0, "StatusNormal", {
|
||||
fg = "#808080",
|
||||
bg = config.bg,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_hl(0, "StatusLsp", {
|
||||
fg = "#61afef",
|
||||
bg = config.bg,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_hl(0, "StatusWarn", {
|
||||
fg = "#e5c07b",
|
||||
bg = config.bg,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_hl(0, "StatusError", {
|
||||
fg = "#e06c75",
|
||||
bg = config.bg,
|
||||
})
|
||||
|
||||
_G.StatusBar = build
|
||||
|
||||
vim.o.statusline = "%!v:lua.StatusBar()"
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,58 +1,96 @@
|
||||
local M = {}
|
||||
|
||||
local term_buf = nil
|
||||
|
||||
local function open_term_split()
|
||||
vim.cmd('botright vsplit')
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_win_set_buf(win, term_buf)
|
||||
else
|
||||
vim.cmd('terminal')
|
||||
term_buf = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
vim.api.nvim_win_set_width(win, math.floor(vim.o.columns * 0.37))
|
||||
vim.cmd('startinsert')
|
||||
vim.cmd("botright vsplit")
|
||||
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_win_set_buf(win, term_buf)
|
||||
else
|
||||
vim.cmd("terminal")
|
||||
term_buf = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
vim.api.nvim_win_set_width(win, math.floor(vim.o.columns * 0.37))
|
||||
vim.cmd("startinsert")
|
||||
end
|
||||
|
||||
local function toggle_term()
|
||||
-- Check if terminal is already visible in a window
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if vim.api.nvim_win_get_buf(win) == term_buf then
|
||||
vim.api.nvim_win_close(win, false)
|
||||
return
|
||||
end
|
||||
end
|
||||
open_term_split()
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if vim.api.nvim_win_get_buf(win) == term_buf then
|
||||
vim.api.nvim_win_close(win, false)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
open_term_split()
|
||||
end
|
||||
|
||||
local function open_term_fullscreen()
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_set_current_buf(term_buf)
|
||||
else
|
||||
vim.cmd('terminal')
|
||||
term_buf = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
vim.cmd('startinsert')
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_set_current_buf(term_buf)
|
||||
else
|
||||
vim.cmd("terminal")
|
||||
term_buf = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
vim.cmd("startinsert")
|
||||
end
|
||||
|
||||
local function prev_non_term_buf()
|
||||
local cur = vim.api.nvim_get_current_buf()
|
||||
local bufs = vim.fn.getbufinfo({ buflisted = 1 })
|
||||
local candidates = {}
|
||||
for _, info in ipairs(bufs) do
|
||||
if info.bufnr ~= cur and vim.bo[info.bufnr].buftype ~= 'terminal' then
|
||||
table.insert(candidates, info)
|
||||
end
|
||||
end
|
||||
if #candidates == 0 then
|
||||
print('No previous non-terminal buffer')
|
||||
return
|
||||
end
|
||||
table.sort(candidates, function(a, b) return a.lastused > b.lastused end)
|
||||
vim.api.nvim_set_current_buf(candidates[1].bufnr)
|
||||
local current = vim.api.nvim_get_current_buf()
|
||||
local buffers = vim.fn.getbufinfo({ buflisted = 1 })
|
||||
local candidates = {}
|
||||
|
||||
for _, buffer in ipairs(buffers) do
|
||||
if buffer.bufnr ~= current and vim.bo[buffer.bufnr].buftype ~= "terminal" then
|
||||
table.insert(candidates, buffer)
|
||||
end
|
||||
end
|
||||
|
||||
if #candidates == 0 then
|
||||
print("No previous non-terminal buffer")
|
||||
return
|
||||
end
|
||||
|
||||
table.sort(candidates, function(a, b)
|
||||
return a.lastused > b.lastused
|
||||
end)
|
||||
|
||||
vim.api.nvim_set_current_buf(candidates[1].bufnr)
|
||||
end
|
||||
|
||||
map('n', '<C-j>', toggle_term, { desc = 'Toggle terminal split' })
|
||||
map('n', '<C-o>', open_term_fullscreen, { desc = 'Open terminal fullscreen' })
|
||||
map('t', '<C-o>', prev_non_term_buf, { desc = 'Exit terminal mode' })
|
||||
map('t', '<C-j>', toggle_term, { desc = 'Toggle terminal split' })
|
||||
map('t', '<C-o>', prev_non_term_buf, { desc = 'Exit terminal mode' })
|
||||
function M.setup()
|
||||
local map = vim.keymap.set
|
||||
|
||||
map("n", "<C-j>", toggle_term, { desc = "Toggle terminal split", })
|
||||
map("n", "<C-o>", open_term_fullscreen, { desc = "Open terminal fullscreen", })
|
||||
map("t", "<C-j>", toggle_term, { desc = "Toggle terminal split", })
|
||||
map("t", "<C-o>", prev_non_term_buf, { desc = "Return to previous buffer", })
|
||||
end
|
||||
|
||||
function M.send(command)
|
||||
local terminal_visible = false
|
||||
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if term_buf and vim.api.nvim_win_get_buf(win) == term_buf then
|
||||
terminal_visible = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not terminal_visible then
|
||||
open_term_split()
|
||||
end
|
||||
|
||||
local job = vim.b[term_buf].terminal_job_id
|
||||
|
||||
if job then
|
||||
vim.api.nvim_chan_send(job, command .. "\n")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
require("tree-sitter-manager").setup()
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user