jones-nvim-config/lua/keymaps.lua

70 lines
2.4 KiB
Lua
Raw Normal View History

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 }
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 = {
-- highlighting
2024-04-07 03:14:14 +00:00
["<leader>nh"] = ":nohl<CR>",
-- 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>",
-- LSP
2024-04-07 03:14:14 +00:00
["<leader>ls"] = ":lspstop<CR>",
["<leader>lo"] = ":lspstart<CR>",
-- 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>",
["<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 = {
["<C-Space>"] = { 'copilot#Accept("<CR>")', expr = true },
["<A-l>"] = "<esc>",
2024-04-07 03:14:14 +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
-- 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
-- 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
-- For simple string command mappings
2024-04-07 03:14:14 +00:00
keymap(mode, key, mapping, opts)
end
end
end