move functions from cmds.lua to utils.lua
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -31,8 +31,8 @@ vmap(">", ">gv")
|
||||
|
||||
-- Terminal
|
||||
tmap("<ESC>", "<C-\\><C-n>") -- Escape - in terminal mode, quit to normal mode
|
||||
nmap("Th", ":lua require('user.cmds').open_terminal()<CR>") -- Shift+t - open terminal in horizontal split
|
||||
nmap("Tv", ":lua require('user.cmds').open_terminal(true)<CR>") -- Shift+t+v - open terminal in vertical split
|
||||
nmap("Th", ":lua require('user.utils').open_terminal()<CR>") -- Shift+t - open terminal in horizontal split
|
||||
nmap("Tv", ":lua require('user.utils').open_terminal(true)<CR>") -- Shift+t+v - open terminal in vertical split
|
||||
|
||||
-- Tabs
|
||||
nmap("H", ":tabprev<CR>") -- Shift+h - open previous tab
|
||||
@@ -55,7 +55,7 @@ nmap("<F2>", ":lua vim.lsp.buf.rename()<CR>") -- F2 - Rename thing under the cur
|
||||
nmap("<leader>.", ":lua vim.lsp.buf.code_action()<CR>") -- Leader+. - show code actions to run
|
||||
vmap("<leader>.", ":lua vim.lsp.buf.range_code_action()<CR>") -- same as above but for visual mode
|
||||
nmap("<leader>dd", ':lua vim.diagnostic.open_float(nil, {focus = false, scope = "cursor"})<CR>') -- Leader+d - show diagnostics in float window
|
||||
nmap("<leader>dy", ":lua require('user.cmds').copy_diagnostic_message()<CR>") -- Leader+d+c - copy diagnostic message
|
||||
nmap("<leader>dy", ":lua require('user.utils').copy_diagnostic_message()<CR>") -- Leader+d+c - copy diagnostic message
|
||||
|
||||
-- Git
|
||||
nmap("<leader>gg", ":G<CR>") -- Leader+g+g - open vim-fugitive window
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user