Make jump to term selector use fzf

This commit is contained in:
Alexander Rosenberg 2022-12-03 22:54:50 -08:00
parent 7a42c9ecf5
commit af45712b8b
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730
2 changed files with 18 additions and 23 deletions

View File

@ -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 :<leader>t jump-or-open-terminal)))
;; Nvim surround
(use! :kylechui/nvim-surround

View File

@ -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 :<leader>t jump-or-open-terminal)
;; Some keybindings for diagnostics
(bind! :n :<leader>e vim.diagnostic.open_float)
(bind! :n "[d" vim.diagnostic.goto_prev)