floatingterminal.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. return {
  2. {
  3. "voldikss/vim-floaterm",
  4. enabled = true,
  5. lazy = false,
  6. config = function()
  7. -- Floaterm config
  8. vim.g.floaterm_autoinsert = true
  9. vim.g.floaterm_autohide = 2
  10. vim.g.floaterm_autoclose = 1
  11. vim.g.floaterm_borderchars = "-¦-¦⌌⌍⌏⌎"
  12. vim.g.floaterm_opener = "vsplit"
  13. -- Config for interacting with terminals
  14. vim.g.floaterm_lastused = ""
  15. local term_group = vim.api.nvim_create_augroup("terminal",
  16. { clear = true })
  17. local terminal_callback = function()
  18. vim.wo.colorcolumn = tostring(-1)
  19. vim.opt.stc = ""
  20. vim.b.number = false
  21. vim.b.relativenumber = false
  22. vim.b.winfixwidth = false
  23. end
  24. vim.api.nvim_create_autocmd({ "TermOpen" }, {
  25. pattern = { "*" },
  26. group = term_group,
  27. callback = terminal_callback
  28. })
  29. vim.api.nvim_create_autocmd({ "BufWinEnter", "WinEnter" }, {
  30. pattern = { "term://*" },
  31. group = term_group,
  32. callback = function()
  33. terminal_callback();
  34. vim.cmd(":startinsert");
  35. end
  36. })
  37. vim.api.nvim_create_autocmd({ "BufEnter" }, {
  38. pattern = { "*" },
  39. group = term_group,
  40. callback = function()
  41. vim.defer_fn(function()
  42. vim.schedule(function()
  43. if (vim.bo.filetype ~= "floaterm") then
  44. vim.cmd(":FloatermHide " ..
  45. vim.g.floaterm_lastused)
  46. end
  47. end)
  48. end, 100)
  49. end
  50. })
  51. -- Configure eight homerow terminals
  52. function MakeTerm(shortcut, name, command, options)
  53. vim.cmd(":nnoremap " .. shortcut ..
  54. " :lua vim.g.floaterm_lastused='" .. name ..
  55. "'; vim.api.nvim_exec2(\"FloatermShow " .. name ..
  56. "\", {})<CR>")
  57. vim.cmd(":FloatermNew --name=" .. name .. " --title=" .. name ..
  58. " --silent --titleposition=left " .. options ..
  59. " /bin/zsh -c \"while true; do; " .. command ..
  60. "; done;\"")
  61. end
  62. MakeTerm("stt", "Alpha", "clear; zsh", "--width=1.0 --height=0.99")
  63. MakeTerm("sts", "Beta", "clear; zsh", "--width=1.0 --height=0.99")
  64. MakeTerm("str", "Gamma", "clear; zsh", "--width=1.0 --height=0.99")
  65. MakeTerm("sta", "Delta", "clear; zsh", "--width=1.0 --height=0.99")
  66. MakeTerm("stn", "Epsilon", "clear; zsh", "--width=80 --height=40")
  67. MakeTerm("ste", "Zeta", "/bin/zsh ~/.scripts/omniscratch.zsh",
  68. "--width=80 --height=40")
  69. MakeTerm("sti", "Eta", "lazydocker", "--width=2.0 --height=2.0")
  70. MakeTerm("sto", "Theta", "lazygit", "--width=2.0 --height=2.0")
  71. -- Keymaps
  72. vim.keymap.set("t", "<Esc><Esc>", "<C-\\><C-n>:FloatermHide<CR>")
  73. vim.keymap.set("t", "<Esc><Space>", "<Esc>")
  74. vim.keymap.set("t", "<C-S-t>", "<C-\\><C-n>")
  75. vim.keymap.set("t", "<S-Space>", "<Esc>")
  76. vim.keymap.set("t", "<A-up>", "<C-\\><C-n>:FloatermHide<CR>")
  77. vim.keymap.set("t", "<A-down>", "<C-\\><C-n>:FloatermNext<CR>")
  78. end
  79. }
  80. }