Explorar o código

fix(neovim): replace `vim-floaterm` with custom plugin

Joe hai 1 ano
pai
achega
af68ed610a

+ 0 - 1
.config/nvim/custom/jonathandarker/lua/jonathandarker/colors/plugins/init.lua

@@ -9,7 +9,6 @@ return {
         require("jonathandarker.colors.plugins.gitsigns").load(p)
         require("jonathandarker.colors.plugins.nvim-treesitter-context").load(p)
         require("jonathandarker.colors.plugins.telescope-nvim").load(p)
-        require("jonathandarker.colors.plugins.vim-floaterm").load(p)
         require("jonathandarker.colors.plugins.status-beast").load(p)
         require("jonathandarker.colors.plugins.jxdash").load(p)
     end

+ 0 - 1
.config/nvim/custom/jonathandarker/lua/jonathandarker/colors/plugins/vim-floaterm.lua

@@ -1 +0,0 @@
-return { load = function(p) p.link("FloatermBorder", "WinSeparator") end }

+ 52 - 0
.config/nvim/custom/like-a-butterfly/lua/like-a-butterfly/init.lua

@@ -0,0 +1,52 @@
+local buffers = {}
+
+local create_term = function(name, command)
+    if buffers[name] == nil then
+        buffers[name] = command
+    end
+end
+
+local open_term = function(name)
+    if buffers[name] == nil then
+        return
+    end
+    local fresh = false
+    if type(buffers[name]) == "string" then
+        fresh = buffers[name]
+        buffers[name] = vim.api.nvim_create_buf(false, true)
+        vim.bo[buffers[name]].filetype = "butterfly"
+    end
+    local win = vim.api.nvim_open_win(buffers[name], true, {
+        relative = 'editor',
+        row = 2,
+        col = 0,
+        width = vim.o.columns,
+        height = vim.o.lines - 2,
+        style = 'minimal',
+        border = 'none',
+    })
+    vim.fn.setwinvar(win, '&winhl', 'Normal:Normal')
+    vim.cmd(":startinsert");
+    if fresh ~= false then
+        vim.fn.termopen({ 'zsh', '-c', 'while true; do; clear; ' ..
+        fresh .. '; done;' })
+    end
+end
+
+local close_all = function()
+    for _, win in pairs(vim.api.nvim_list_wins()) do
+        local winbuf = vim.api.nvim_win_get_buf(win)
+        if vim.bo[winbuf].filetype == 'butterfly' then
+            vim.api.nvim_win_hide(win)
+        end
+    end
+end
+
+return {
+    create_term = create_term,
+    open_term = open_term,
+    close_all = close_all,
+    buffers = function()
+        return buffers
+    end
+}

+ 40 - 66
.config/nvim/lua/plugins/floatingterminal.lua

@@ -1,81 +1,55 @@
 return {
     {
-        "voldikss/vim-floaterm",
+        dir = "../custom/like-a-butterfly",
+        name = "like-a-butterfly",
         enabled = true,
         lazy = false,
         config = function()
-            -- Floaterm config
-            vim.g.floaterm_autoinsert = true
-            vim.g.floaterm_autohide = 2
-            vim.g.floaterm_autoclose = 1
-            vim.g.floaterm_borderchars = "-¦-¦⌌⌍⌏⌎"
-            vim.g.floaterm_opener = "vsplit"
-            -- Config for interacting with terminals
-            vim.g.floaterm_lastused = ""
-            local term_group = vim.api.nvim_create_augroup("terminal",
-                { clear = true })
-            local terminal_callback = function()
-                vim.wo.colorcolumn = tostring(-1)
-                vim.opt.stc = ""
-                vim.b.number = false
-                vim.b.relativenumber = false
-                vim.b.winfixwidth = false
-            end
-            vim.api.nvim_create_autocmd({ "TermOpen" }, {
-                pattern = { "*" },
-                group = term_group,
-                callback = terminal_callback
-            })
-            vim.api.nvim_create_autocmd({ "BufWinEnter", "WinEnter" }, {
-                pattern = { "term://*" },
-                group = term_group,
-                callback = function()
-                    terminal_callback();
-                    vim.cmd(":startinsert");
-                end
-            })
-            vim.api.nvim_create_autocmd({ "BufEnter" }, {
-                pattern = { "*" },
-                group = term_group,
-                callback = function()
-                    vim.defer_fn(function()
-                        vim.schedule(function()
-                            if (vim.bo.filetype ~= "floaterm") then
-                                vim.cmd(":FloatermHide " ..
-                                    vim.g.floaterm_lastused)
-                            end
-                        end)
-                    end, 100)
-                end
-            })
+            local lab = require('like-a-butterfly')
             -- Configure eight homerow terminals
-            function MakeTerm(shortcut, name, command, options)
-                vim.cmd(":nnoremap " .. shortcut ..
-                    " :lua vim.g.floaterm_lastused='" .. name ..
-                    "'; vim.api.nvim_exec2(\"FloatermShow " .. name ..
-                    "\", {})<CR>")
-                vim.cmd(":FloatermNew --name=" .. name .. " --title=" .. name ..
-                    " --silent --titleposition=left " .. options ..
-                    " /bin/zsh -c \"while true; do; " .. command ..
-                    "; done;\"")
+            function MakeTerm(shortcut, name, command)
+                lab.create_term(name, command)
+                vim.keymap.set("n", shortcut, function()
+                    lab.open_term(name)
+                end)
             end
 
-            MakeTerm("stt", "Alpha", "clear; zsh", "--width=1.0 --height=0.99")
-            MakeTerm("sts", "Beta", "clear; zsh", "--width=1.0 --height=0.99")
-            MakeTerm("str", "Gamma", "clear; zsh", "--width=1.0 --height=0.99")
-            MakeTerm("sta", "Delta", "clear; zsh", "--width=1.0 --height=0.99")
-            MakeTerm("stn", "Epsilon", "clear; zsh", "--width=80 --height=40")
-            MakeTerm("ste", "Zeta", "/bin/zsh ~/.scripts/omniscratch.zsh",
-                "--width=80 --height=40")
-            MakeTerm("sti", "Eta", "lazydocker", "--width=2.0 --height=2.0")
-            MakeTerm("sto", "Theta", "lazygit", "--width=2.0 --height=2.0")
+            vim.api.nvim_create_autocmd({ "BufEnter" },
+                {
+                    pattern = { "*" },
+                    group = vim.api.nvim_create_augroup(
+                        'like-a-butterfly', { clear = true }),
+                    callback = function()
+                        vim
+                            .schedule(function()
+                                if (vim.bo.filetype ~= "butterfly") then
+                                    lab.close_all()
+                                else
+                                    vim.api.nvim_feedkeys(
+                                        vim.api.nvim_replace_termcodes(
+                                            '<C-\\><C-n>^zei',
+                                            true, true, true), 'i', true)
+                                    vim.cmd("set sidescrolloff=" .. vim.o
+                                        .columns)
+                                    vim.cmd("redraw!")
+                                end
+                            end)
+                    end
+                })
+            MakeTerm("stt", "Alpha", "zsh")
+            MakeTerm("sts", "Beta", "zsh")
+            MakeTerm("str", "Gamma", "zsh")
+            MakeTerm("sta", "Delta", "zsh")
+            MakeTerm("stn", "Epsilon", "zsh")
+            MakeTerm("ste", "Zeta", "/bin/zsh ~/.scripts/omniscratch.zsh")
+            MakeTerm("sti", "Eta", "lazydocker")
+            MakeTerm("sto", "Theta", "lazygit")
+
             -- Keymaps
-            vim.keymap.set("t", "<Esc><Esc>", "<C-\\><C-n>:FloatermHide<CR>")
+            vim.keymap.set("t", "<Esc><Esc>", lab.close_all)
             vim.keymap.set("t", "<Esc><Space>", "<Esc>")
             vim.keymap.set("t", "<C-S-t>", "<C-\\><C-n>")
             vim.keymap.set("t", "<S-Space>", "<Esc>")
-            vim.keymap.set("t", "<A-up>", "<C-\\><C-n>:FloatermHide<CR>")
-            vim.keymap.set("t", "<A-down>", "<C-\\><C-n>:FloatermNext<CR>")
         end
     }
 }

+ 0 - 7
.config/zsh/.zshrc

@@ -87,13 +87,6 @@ fi
 # Aliases
 ################################################################################
 
-# Redirect Neovim when running ZSH in Vim's Floaterm
-if command -v floaterm &> /dev/null
-then
-    alias n="floaterm"
-    alias nvim="floaterm"
-fi
-
 ################################################################################
 # fzf
 ################################################################################