diff --git a/config/nvim/lua/user/cmds.lua b/config/nvim/lua/user/cmds.lua index b329d56..e69de29 100644 --- a/config/nvim/lua/user/cmds.lua +++ b/config/nvim/lua/user/cmds.lua @@ -1,32 +0,0 @@ -local yank = require("user.utils").yank - -local M = {} - -M.open_terminal = function(vertically) - vertically = vertically or false - - if vertically then - vim.cmd(":vs term://bash") - else - vim.cmd(":split term://bash") - end -end - -M.copy_diagnostic_message = function() - local diagnostics = vim.lsp.diagnostic.get_line_diagnostics() - - if #diagnostics == 0 then - print("No diagnostics to yank") - return - end - - -- TODO: print all messages available and prompt which one to yank - - local message = diagnostics[1].message - - yank(message) - - print("Diagnostic message was yanked") -end - -return M diff --git a/config/nvim/lua/user/remaps.lua b/config/nvim/lua/user/remaps.lua index a6ec12e..82810e9 100644 --- a/config/nvim/lua/user/remaps.lua +++ b/config/nvim/lua/user/remaps.lua @@ -31,8 +31,8 @@ vmap(">", ">gv") -- Terminal tmap("", "") -- Escape - in terminal mode, quit to normal mode -nmap("Th", ":lua require('user.cmds').open_terminal()") -- Shift+t - open terminal in horizontal split -nmap("Tv", ":lua require('user.cmds').open_terminal(true)") -- Shift+t+v - open terminal in vertical split +nmap("Th", ":lua require('user.utils').open_terminal()") -- Shift+t - open terminal in horizontal split +nmap("Tv", ":lua require('user.utils').open_terminal(true)") -- Shift+t+v - open terminal in vertical split -- Tabs nmap("H", ":tabprev") -- Shift+h - open previous tab @@ -55,7 +55,7 @@ nmap("", ":lua vim.lsp.buf.rename()") -- F2 - Rename thing under the cur nmap(".", ":lua vim.lsp.buf.code_action()") -- Leader+. - show code actions to run vmap(".", ":lua vim.lsp.buf.range_code_action()") -- same as above but for visual mode nmap("dd", ':lua vim.diagnostic.open_float(nil, {focus = false, scope = "cursor"})') -- Leader+d - show diagnostics in float window -nmap("dy", ":lua require('user.cmds').copy_diagnostic_message()") -- Leader+d+c - copy diagnostic message +nmap("dy", ":lua require('user.utils').copy_diagnostic_message()") -- Leader+d+c - copy diagnostic message -- Git nmap("gg", ":G") -- Leader+g+g - open vim-fugitive window diff --git a/config/nvim/lua/user/utils.lua b/config/nvim/lua/user/utils.lua index 393bb9a..8e0143e 100644 --- a/config/nvim/lua/user/utils.lua +++ b/config/nvim/lua/user/utils.lua @@ -47,4 +47,57 @@ M.yank = function(message) end end +M.get_hidden_buffers = function() + local buffers = vim.api.nvim_list_bufs() + + local hidden_buffers = {} + + for _, bufnr in ipairs(buffers) do + local buf = vim.fn.getbufinfo(bufnr)[1] + + if buf.hidden == 1 then + table.insert(hidden_buffers, { bufnr = buf.bufnr, name = buf.name }) + end + end +end + +M.delete_noname_buffers = function() + local buffers = M.get_hidden_buffers() + + for _, buf in ipairs(buffers) do + if buf.name == "" then + vim.cmd("bd " .. buf.bufnr) + end + end + + print("Deleted " .. #buffers .. " buffers") +end + +M.copy_diagnostic_message = function() + local diagnostics = vim.lsp.diagnostic.get_line_diagnostics() + + if #diagnostics == 0 then + print("No diagnostics to yank") + return + end + + -- TODO: print all messages available and prompt which one to yank + + local message = diagnostics[1].message + + M.yank(message) + + print("Diagnostic message was yanked") +end + +M.open_terminal = function(vertically) + vertically = vertically or false + + if vertically then + vim.cmd(":vs term://bash") + else + vim.cmd(":split term://bash") + end +end + return M