summaryrefslogtreecommitdiff
path: root/lua/binds.lua
blob: f705eb7fcc3aa16ec05096fc4af6babfb07d3104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--
-- Configuration Tools
--
local ct = require('conftool')
-- local defs = require('defs')

--
-- Maps
--
-- select all
-- ct.map('n', '<Leader>a', '<esc>ggVG<CR>')
--[[
-- spawn terminal
ct.map('n', '<C-M-t>', ':!' .. defs.external_term .. ' . &<CR><CR>')
-- spwan file manager
ct.map('n', '<C-M-f>', ':!' .. defs.external_filemgr .. ' . &<CR><CR>')
]]
-- spellchecking
ct.map('n', '<Leader>s', ':set spell!<CR>')

-- Buffer Navigation
ct.map('n', '<Leader>w', '<cmd>bnext<CR>')
ct.map('n', '<Leader>W', '<cmd>bprevious<CR>')

-- close buffer
ct.map('n', '<Leader>q', ':bd<CR>')
ct.map('n', '<Leader>wq', '<cmd>w<CR><cmd>bd<CR>')

-- netrw
ct.map('n', '<Leader>e', '<cmd>Explore<CR>')

--
-- LSP
--
local lsp_buf = vim.lsp.buf

-- Function to convert snake_case to PascalCase
local function snake_to_pascal(name)
	return name:gsub('_', ''):gsub("(%a)(%w*)", function(first, rest) 
		return first:upper() .. rest:lower()
	end)
end

for func_name, _ in pairs(lsp_buf) do
	if type(lsp_buf[func_name]) == "function" then -- Check if the value is a function
		local command_name = 'Lb' .. snake_to_pascal(func_name)
		vim.api.nvim_create_user_command(
			command_name,
			function()
				lsp_buf[func_name]()  -- Call the function from the table
			end,
			{desc = "Run LSP Buffer Function: " .. func_name}
		)
	end
end

-- function toggle_background()
--   local bg = vim.o.background
-- 
--   if bg == "dark" then
--     vim.cmd("set background=light")
--   else
--     vim.cmd("set background=dark")
--   end
-- 
--   -- Query the current colorscheme
--   --[[ local colorscheme = vim.fn.executable('colorscheme') or ""
--   -- colorscheme = colorscheme:match("^%s*(.-)%s*$")
-- 
--   -- Reload the colorscheme if it was set
--   if colorscheme ~= "" then
--     vim.cmd("colorscheme " .. colorscheme)
--   end ]]--
-- end
-- ct.map('n', '<Leader>c', '<cmd>lua toggle_background()<CR>')
ct.map('n', '<Leader>b', ':buffer<Space><C-z>')
ct.map('n', '<Leader>h', '<cmd>lua vim.lsp.buf.hover()<CR>')
--
-- Commands
--
-- ct.defcmd('Xrdb', '!xrdb %')
-- ct.defcmd('ExTerm', '!' .. defs.external_term .. '&<CR><CR>')
-- ct.defcmd('ExFileMgr', '!' .. defs.external_filemgr .. '. &<CR><CR>')