From f4ab374ed3e3b967feee10f4a0e25ae2510880fe Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 21 Dec 2024 22:50:20 +0100 Subject: [PATCH] feat(nvim): clean up terminal config --- nvim-fredrik/lua/fredrik/config/keymaps.lua | 16 +++---- .../lua/fredrik/plugins/core/fterm.lua | 17 ++++++++ nvim-fredrik/lua/fredrik/plugins/fterm.lua | 12 ------ nvim-fredrik/lua/fredrik/utils/terminal.lua | 42 ------------------- 4 files changed, 23 insertions(+), 64 deletions(-) create mode 100644 nvim-fredrik/lua/fredrik/plugins/core/fterm.lua delete mode 100644 nvim-fredrik/lua/fredrik/plugins/fterm.lua delete mode 100644 nvim-fredrik/lua/fredrik/utils/terminal.lua diff --git a/nvim-fredrik/lua/fredrik/config/keymaps.lua b/nvim-fredrik/lua/fredrik/config/keymaps.lua index 20366cdf..7f077472 100644 --- a/nvim-fredrik/lua/fredrik/config/keymaps.lua +++ b/nvim-fredrik/lua/fredrik/config/keymaps.lua @@ -878,7 +878,7 @@ function M.setup_noice_keymaps() map_normal_mode("snL", ":NoiceLog", "[s]earch [n]oice [L]og") end -function M.setup_terminal_keymaps() +function M.setup_fterm_keymaps() -- Both and are mapped due to the way control characters are interpreted by terminal emulators. -- ASCII value of '/' is 47, and of '_' is 95. When is pressed, the terminal sends (47 - 64) which wraps around to 111 ('o'). -- When is pressed, the terminal sends (95 - 64) which is 31. Hence, both key combinations need to be mapped. @@ -886,21 +886,17 @@ function M.setup_terminal_keymaps() -- toggles the floating terminal local ctrl_slash = "" local ctrl_underscore = "" - local ctrl_alt_slash = "" - local ctrl_alt_underscore = "" + -- local ctrl_alt_slash = "" + -- local ctrl_alt_underscore = "" local floating_term_cmd = function() vim.api.nvim_set_keymap("t", "", "", { noremap = true }) - require("fredrik.utils.terminal").toggle_fterm() - end - local split_term_cmd = function() - vim.api.nvim_set_keymap("t", "", "", { noremap = true }) - require("fredrik.utils.terminal").toggle_terminal_native() + require("FTerm").toggle() end return { - { ctrl_alt_slash, split_term_cmd, mode = { "n", "i", "t", "v" }, desc = "Toggle terminal" }, - { ctrl_alt_underscore, split_term_cmd, mode = { "n", "i", "t", "v" }, desc = "Toggle terminal" }, + -- { ctrl_alt_slash, split_term_cmd, mode = { "n", "i", "t", "v" }, desc = "Toggle terminal" }, + -- { ctrl_alt_underscore, split_term_cmd, mode = { "n", "i", "t", "v" }, desc = "Toggle terminal" }, -- C-A-/ toggles split terminal on/off { ctrl_slash, floating_term_cmd, mode = { "n", "i", "t", "v" }, desc = "Toggle native terminal" }, diff --git a/nvim-fredrik/lua/fredrik/plugins/core/fterm.lua b/nvim-fredrik/lua/fredrik/plugins/core/fterm.lua new file mode 100644 index 00000000..9175f961 --- /dev/null +++ b/nvim-fredrik/lua/fredrik/plugins/core/fterm.lua @@ -0,0 +1,17 @@ +return { + + { + "numToStr/FTerm.nvim", + lazy = true, + opts = { + dimensions = { + height = 0.9, + width = 0.9, + }, + }, + config = function(_, opts) + require("FTerm").setup(opts) + end, + keys = require("fredrik.config.keymaps").setup_fterm_keymaps(), + }, +} diff --git a/nvim-fredrik/lua/fredrik/plugins/fterm.lua b/nvim-fredrik/lua/fredrik/plugins/fterm.lua deleted file mode 100644 index 795bab8c..00000000 --- a/nvim-fredrik/lua/fredrik/plugins/fterm.lua +++ /dev/null @@ -1,12 +0,0 @@ -return { - - { - "numToStr/FTerm.nvim", - lazy = true, - opts = {}, - config = function(_, opts) - require("FTerm").setup(opts) - end, - keys = require("fredrik.config.keymaps").setup_terminal_keymaps(), - }, -} diff --git a/nvim-fredrik/lua/fredrik/utils/terminal.lua b/nvim-fredrik/lua/fredrik/utils/terminal.lua deleted file mode 100644 index de273e5a..00000000 --- a/nvim-fredrik/lua/fredrik/utils/terminal.lua +++ /dev/null @@ -1,42 +0,0 @@ -M = {} - -function M.toggle_terminal_native() - -- If the terminal buffer doesn't exist or is no longer valid... - if not vim.g.terminal_buf or not vim.api.nvim_buf_is_valid(vim.g.terminal_buf) then - -- Create a new terminal buffer - vim.g.terminal_buf = vim.api.nvim_create_buf(false, true) - vim.api.nvim_buf_set_option(vim.g.terminal_buf, "buftype", "nofile") -- FIXME: deprecated - vim.api.nvim_buf_call(vim.g.terminal_buf, function() - vim.cmd("terminal") - end) - end - -- If the terminal window doesn't exist or is no longer valid... - if not vim.g.terminal_win or not vim.api.nvim_win_is_valid(vim.g.terminal_win) then - -- Create a new split window and display the terminal buffer in it - vim.cmd("split") - vim.g.terminal_win = vim.api.nvim_get_current_win() - vim.api.nvim_win_set_buf(vim.g.terminal_win, vim.g.terminal_buf) - else - -- If the terminal window is the current window, hide it - if vim.api.nvim_get_current_win() == vim.g.terminal_win then - vim.api.nvim_win_hide(vim.g.terminal_win) - else -- Otherwise, switch to the terminal window - vim.api.nvim_set_current_win(vim.g.terminal_win) - end - end -end - -function M.toggle_fterm() - require("FTerm").toggle() -end - -function M.toggle_toggleterm() - -- NOTE: this requires toggleterm - local cwd = vim.fn.getcwd() - local cwd_folder_name = vim.fn.fnamemodify(cwd, ":t") - - local cmd = ":ToggleTerm size=40 dir=" .. cwd .. " direction=horizontal name=" .. cwd_folder_name - vim.cmd(cmd) -end - -return M