2024-04-07 21:09:45 +00:00
|
|
|
local fterm = require('FTerm')
|
2024-04-07 03:14:14 +00:00
|
|
|
local keymap = vim.api.nvim_set_keymap
|
|
|
|
local opts = { noremap = true, silent = true }
|
2024-04-07 21:09:45 +00:00
|
|
|
local api = vim.api
|
|
|
|
|
|
|
|
-- Custom commands
|
|
|
|
api.nvim_create_user_command('FTermToggle', fterm.toggle, { bang = true })
|
|
|
|
api.nvim_create_user_command('FTermClose', fterm.close, { bang = true })
|
2024-04-07 03:14:14 +00:00
|
|
|
|
|
|
|
local mappings = {
|
|
|
|
n = {
|
2024-04-07 21:09:45 +00:00
|
|
|
-- highlighting
|
2024-04-07 03:14:14 +00:00
|
|
|
["<leader>nh"] = ":nohl<CR>",
|
2024-04-07 21:09:45 +00:00
|
|
|
-- move between buffers
|
|
|
|
["<c-h>"] = "<C-w>h",
|
|
|
|
["<c-j>"] = "<C-w>j",
|
|
|
|
["<c-k>"] = "<C-w>k",
|
|
|
|
["<c-l>"] = "<C-w>l",
|
|
|
|
-- open and close buggers
|
2024-04-07 03:14:14 +00:00
|
|
|
["<leader>sv"] = "<C-w>s",
|
|
|
|
["<leader>sh"] = "<C-w>v",
|
|
|
|
["<leader>se"] = "<C-w>=",
|
|
|
|
["<leader>sx"] = ":close<CR>",
|
|
|
|
-- nvim-tree
|
|
|
|
["<leader>e"] = ":NvimTreeToggle<CR>",
|
|
|
|
["<leader>cf"] = ":NvimTreeCollapse<CR>",
|
2024-04-07 21:09:45 +00:00
|
|
|
-- LSP
|
2024-04-07 03:14:14 +00:00
|
|
|
["<leader>ls"] = ":lspstop<CR>",
|
|
|
|
["<leader>lo"] = ":lspstart<CR>",
|
2024-04-07 21:09:45 +00:00
|
|
|
-- Telescope
|
2024-04-07 03:14:14 +00:00
|
|
|
["<leader>ff"] = "<cmd>Telescope find_files<CR>",
|
|
|
|
["<leader>fw"] = "<cmd>Telescope live_grep<CR>",
|
|
|
|
["<leader>fc"] = "<cmd>Telescope grep_string<CR>",
|
|
|
|
["<leader>th"] = "<cmd>Themery<CR>",
|
2024-04-07 21:09:45 +00:00
|
|
|
["<leader>sm"] = ":MaximizerToggle<CR>",
|
|
|
|
-- FTerm
|
|
|
|
["<leader>h"] = "<cmd>FTermToggle<CR>"
|
2024-04-07 03:14:14 +00:00
|
|
|
},
|
|
|
|
x = {
|
|
|
|
["<A-j>"] = ":move '>+1<CR>gv-gv",
|
|
|
|
["<A-k>"] = ":move '<-2<CR>gv-gv",
|
|
|
|
},
|
|
|
|
i = {
|
2024-04-07 21:09:45 +00:00
|
|
|
["<C-Space>"] = { 'copilot#Accept("<CR>")', expr = true },
|
|
|
|
["<A-l>"] = "<esc>",
|
2024-04-07 03:14:14 +00:00
|
|
|
},
|
2024-04-07 21:09:45 +00:00
|
|
|
t = {
|
|
|
|
["A-l"] = "<cmd>FTermClose<CR>"
|
|
|
|
}
|
2024-04-07 03:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for mode, mode_mappings in pairs(mappings) do
|
|
|
|
for key, mapping in pairs(mode_mappings) do
|
|
|
|
if type(mapping) == "function" then
|
2024-04-07 21:09:45 +00:00
|
|
|
-- For direct Lua function calls; ensure your function returns a string command
|
|
|
|
keymap(mode, key, "<cmd>lua " .. mapping() .. "<CR>", opts)
|
|
|
|
elseif type(mapping) == "table" and mapping.expr then
|
|
|
|
-- For expression mappings, like for copilot
|
|
|
|
local expr_opts = vim.tbl_extend("force", opts, { expr = true })
|
|
|
|
keymap(mode, key, mapping[1], expr_opts)
|
2024-04-07 03:14:14 +00:00
|
|
|
elseif type(mapping) == "table" then
|
2024-04-07 21:09:45 +00:00
|
|
|
-- For mappings that have their options specified directly
|
2024-04-07 03:14:14 +00:00
|
|
|
keymap(mode, key, mapping[1], mapping[2] or opts)
|
|
|
|
else
|
2024-04-07 21:09:45 +00:00
|
|
|
-- For simple string command mappings
|
2024-04-07 03:14:14 +00:00
|
|
|
keymap(mode, key, mapping, opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|