Browse Source

dotfiles-nvim: toggleterm

dev_01_initial
Heiko Blobner 3 years ago
parent
commit
7bcd2f471b
  1. 2
      dot_files/.config/nvim/lua/core/plugins/coding/test/core.lua
  2. 54
      dot_files/.config/nvim/lua/core/plugins/editor/flatten-nvim.lua
  3. 45
      dot_files/.config/nvim/lua/core/plugins/editor/toggleterm-nvim.lua

2
dot_files/.config/nvim/lua/core/plugins/coding/test/core.lua

@ -7,7 +7,7 @@ return {
optional = true, optional = true,
opts = { opts = {
defaults = { defaults = {
["<leader>t"] = { name = "+test" }, ["<leader>T"] = { name = "+test" },
}, },
}, },
}, },

54
dot_files/.config/nvim/lua/core/plugins/editor/flatten-nvim.lua

@ -0,0 +1,54 @@
-- Flatten allows you to open files from a neovim terminal buffer in your current neovim instance instead of a nested one:w
return {
'willothy/flatten.nvim',
opts = {
window = { open = 'alternate' },
callbacks = {
should_block = function(argv)
-- Note that argv contains all the parts of the CLI command, including
-- Neovim's path, commands, options and files.
-- See: :help v:argv
-- In this case, we would block if we find the `-b` flag
-- This allows you to use `nvim -b file1` instead of `nvim --cmd 'let g:flatten_wait=1' file1`
return vim.tbl_contains(argv, "-b")
-- Alternatively, we can block if we find the diff-mode option
-- return vim.tbl_contains(argv, "-d")
end,
post_open = function(_bufnr, winnr, _ft, is_blocking)
if is_blocking then
require('toggleterm').toggle(0)
else
vim.api.nvim_set_current_win(winnr)
end
-- If the file is a git commit, create one-shot autocmd to delete its buffer on write
-- If you just want the toggleable terminal integration, ignore this bit
if ft == "gitcommit" then
vim.api.nvim_create_autocmd(
"BufWritePost",
{
buffer = bufnr,
once = true,
callback = function()
-- This is a bit of a hack, but if you run bufdelete immediately
-- the shell can occasionally freeze
vim.defer_fn(
function()
vim.api.nvim_buf_delete(bufnr, {})
end,
50
)
end
}
)
end
end,
block_end = function()
-- After blocking ends (for a git commit, etc), reopen the terminal
require("toggleterm").toggle(0)
end
},
},
}

45
dot_files/.config/nvim/lua/core/plugins/editor/toggleterm-nvim.lua

@ -0,0 +1,45 @@
return {
'akinsho/toggleterm.nvim',
version = "*",
lazy = false,
priority = 1001,
opts = {
open_mapping = [[<c-\>]],
direction = 'float',
shade_terminals = true,
float_opts = {
border = "curved",
}
},
keys = {
{ "<esc>", [[<c-\><c-n>]], mode = 't', desc = "Enter free movement" },
--{ "jk", [[<C-\><C-n>]], mode = 't', desc = "" },
{ "<C-h>", [[<Cmd>wincmd h<CR>]], mode = 't', desc = "Leave"} ,
{ "<C-j>", [[<Cmd>wincmd j<CR>]], mode = 't', desc = "Leave" },
{ "<C-k>", [[<Cmd>wincmd k<CR>]], mode = 't', desc = "Leave" },
{ "<C-l>", [[<Cmd>wincmd l<CR>]], mode = 't', desc = "Leave" },
{ "<C-w>", [[<C-\><C-n><C-w>]], mode = 't', desc = "Leave" },
},
config = function(_, opts)
require('toggleterm').setup(opts)
--
local Terminal = require('toggleterm.terminal').Terminal
local htop = Terminal:new({ cmd = "htop", direction = "horizontal", hidden = true })
function _htop_toggle()
htop:toggle()
end
local lazygit = Terminal:new({ cmd = "lazygit", dir = "git_dir", hidden = true })
function _lazygit_toggle()
lazygit:toggle()
end
vim.api.nvim_set_keymap("n", "<leader>tf", "<cmd>ToggleTerm direction=float<CR>", { desc = "Toggle floating terminal", noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>th", "<cmd>ToggleTerm direction=horizontal size=10<CR>", { desc = "Toggle horizontal terminal", noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>tv", "<cmd>ToggleTerm direction=vertical size=80<CR>", { desc = "Toggle vertical terminal", noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>tg", "<cmd>lua _lazygit_toggle()<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "<leader>tt", "<cmd>lua _htop_toggle()<CR>", {noremap = true, silent = true})
end,
}
Loading…
Cancel
Save