Better binds and terminal support
This commit is contained in:
@@ -67,13 +67,12 @@ vim.cmd.colorscheme('vague')
|
|||||||
-- Lsp specific, uses nvim-lspconfigs with the below
|
-- Lsp specific, uses nvim-lspconfigs with the below
|
||||||
vim.lsp.enable({ "gopls", "ols" })
|
vim.lsp.enable({ "gopls", "ols" })
|
||||||
map("n", "gd", ":lua vim.lsp.buf.definition()<CR>")
|
map("n", "gd", ":lua vim.lsp.buf.definition()<CR>")
|
||||||
map("n", "ld", ":lua vim.diagnostic.open_float()<CR>")
|
map("n", "gr", ":lua vim.lsp.buf.rename()<CR>")
|
||||||
map("n", "lr", ":lua vim.lsp.buf.rename()<CR>")
|
map("n", "ga", ":lua vim.lsp.buf.code_action()<CR>")
|
||||||
map("n", "la", ":lua vim.lsp.buf.code_action()<CR>")
|
|
||||||
|
|
||||||
require("fzf-lua").setup({})
|
require("fzf-lua").setup({})
|
||||||
map("n", "<C-p>", ":FzfLua files<CR>")
|
map("n", "<C-p>", ":FzfLua files<CR>")
|
||||||
map("n", "<C-o>", ":FzfLua buffers<CR>")
|
map("n", "<C-m>", ":FzfLua buffers<CR>")
|
||||||
map("n", "<C-i>", ":FzfLua diagnostics_workspace<CR>")
|
map("n", "<C-i>", ":FzfLua diagnostics_workspace<CR>")
|
||||||
map("n", "<C-f>", ":FzfLua live_grep<CR>")
|
map("n", "<C-f>", ":FzfLua live_grep<CR>")
|
||||||
map("n", "<C-b>", ":FzfLua grep_curbuf<CR>")
|
map("n", "<C-b>", ":FzfLua grep_curbuf<CR>")
|
||||||
@@ -109,3 +108,5 @@ vim.api.nvim_create_autocmd("BufWritePre", {
|
|||||||
vim.fn.setpos(".", save_cursor)
|
vim.fn.setpos(".", save_cursor)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
require("terminal")
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
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')
|
||||||
|
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()
|
||||||
|
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')
|
||||||
|
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)
|
||||||
|
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' })
|
||||||
Reference in New Issue
Block a user