From af45712b8b7be9f0976eae0ea0cdd7ce31ba1835 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sat, 3 Dec 2022 22:54:50 -0800 Subject: [PATCH] Make jump to term selector use fzf --- fnl/plugin.fnl | 19 ++++++++++++++++++- init.fnl | 22 ---------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/fnl/plugin.fnl b/fnl/plugin.fnl index da2edc7..e612e69 100644 --- a/fnl/plugin.fnl +++ b/fnl/plugin.fnl @@ -80,7 +80,24 @@ (let [code (os.execute "git rev-parse --is-inside-work-tree >/dev/null 2>&1")] (if (= code 0) (fzf.git_files) - (fzf.files))))))) + (fzf.files))))) + (fn jump-or-open-terminal [] + "If no terminal buffer exists, create one. Otherwise, open new one." + (var term_count 0) + (var last_id 0) + (var terms [ ]) + (each [_ id (pairs (vim.api.nvim_list_bufs))] + (let [name (vim.api.nvim_buf_get_name id)] + (when (vim.startswith name "term://") + (table.insert terms name) + (set term_count (+ term_count 1)) + (set last_id id)))) + (if (= term_count 0) + (vim.cmd.terminal) + (= term_count 1) + (vim.cmd.buffer last_id) + (fzf.buffers { :query "term://" }))) + (bind! :n :t jump-or-open-terminal))) ;; Nvim surround (use! :kylechui/nvim-surround diff --git a/init.fnl b/init.fnl index f20c8eb..e2edab5 100644 --- a/init.fnl +++ b/init.fnl @@ -81,28 +81,6 @@ #(if (= (vim.fn.buflisted (vim.api.nvim_get_current_buf)) 1) (set vim.opt_local.spell true))) -(fn jump-or-open-terminal [] - "If no terminal buffer exists, create one. Otherwise, open new one." - (var term_count 0) - (var last_id 0) - (var terms [ ]) - (each [_ id (pairs (vim.api.nvim_list_bufs))] - (let [name (vim.api.nvim_buf_get_name id)] - (when (vim.startswith name "term://") - (table.insert terms name) - (set term_count (+ term_count 1)) - (set last_id id)))) - (if (= term_count 0) - (vim.cmd.terminal) - (= term_count 1) - (vim.cmd.buffer last_id) - (vim.ui.select terms - { :prompt "Terminal Buffers" } - (fn [choice] - (when choice - (vim.cmd.buffer choice)))))) -(bind! :n :t jump-or-open-terminal) - ;; Some keybindings for diagnostics (bind! :n :e vim.diagnostic.open_float) (bind! :n "[d" vim.diagnostic.goto_prev)