From 75abeb74f7245c6c2cb3b3de261f8679e3486dca Mon Sep 17 00:00:00 2001 From: jaredgoldman Date: Sun, 7 Apr 2024 17:09:45 -0400 Subject: [PATCH] feat: add sensible copilot accept and term --- init.lua | 1 + lazy-lock.json | 5 +++-- lua/config/fterm.lua | 3 +++ lua/keymaps.lua | 43 +++++++++++++++++++++++++++++++------------ lua/lsp.lua | 9 --------- lua/options.lua | 34 ++++++++++++++++++---------------- lua/plugins.lua | 4 +++- requirements.md | 3 ++- 8 files changed, 61 insertions(+), 41 deletions(-) create mode 100644 lua/config/fterm.lua diff --git a/init.lua b/init.lua index f4409b1..b4ab18a 100644 --- a/init.lua +++ b/init.lua @@ -10,3 +10,4 @@ require("config.comment") require("config.themery") require("config.theme") require("config.lualine") +require("config.fterm") diff --git a/lazy-lock.json b/lazy-lock.json index 092490b..ed552f0 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,14 +1,15 @@ { + "FTerm.nvim": { "branch": "master", "commit": "d1320892cc2ebab472935242d9d992a2c9570180" }, "LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" }, "catppuccin": { "branch": "main", "commit": "aebe43db9cb26e1c70fc5b2fd4158169c405e720" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, - "lazy.nvim": { "branch": "main", "commit": "bef521ac89c8d423f9d092e37b58e8af0c099309" }, + "lazy.nvim": { "branch": "main", "commit": "31ddbea7c10b6920c9077b66c97951ca8682d5c8" }, "lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "9dfcf2036c223920826140f0151d929a43f9eceb" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "44509689b9bf3984d729cc264aacb31cb7f41668" }, "mason.nvim": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" }, "monokai.nvim": { "branch": "master", "commit": "b8bd44d5796503173627d7a1fc51f77ec3a08a63" }, "nvim-cmp": { "branch": "main", "commit": "ce16de5665c766f39c271705b17fff06f7bcb84f" }, diff --git a/lua/config/fterm.lua b/lua/config/fterm.lua new file mode 100644 index 0000000..b9ab0dd --- /dev/null +++ b/lua/config/fterm.lua @@ -0,0 +1,3 @@ +require("FTerm").setup({ + blend = 25 +}) diff --git a/lua/keymaps.lua b/lua/keymaps.lua index fedc054..06cdb37 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -1,9 +1,22 @@ +local fterm = require('FTerm') 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 }) local mappings = { n = { + -- highlighting ["nh"] = ":nohl", + -- move between buffers + [""] = "h", + [""] = "j", + [""] = "k", + [""] = "l", + -- open and close buggers ["sv"] = "s", ["sh"] = "v", ["se"] = "=", @@ -11,39 +24,45 @@ local mappings = { -- nvim-tree ["e"] = ":NvimTreeToggle", ["cf"] = ":NvimTreeCollapse", - -- lsp + -- LSP ["ls"] = ":lspstop", ["lo"] = ":lspstart", - -- move between buffers - [""] = "h", - [""] = "j", - [""] = "k", - [""] = "l", + -- Telescope ["ff"] = "Telescope find_files", ["fw"] = "Telescope live_grep", ["fc"] = "Telescope grep_string", ["th"] = "Themery", - ["sm"] = ":MaximizerToggle" + ["sm"] = ":MaximizerToggle", + -- FTerm + ["h"] = "FTermToggle" }, x = { - ["J"] = ":move '>+1gv-gv", - ["K"] = ":move '<-2gv-gv", [""] = ":move '>+1gv-gv", [""] = ":move '<-2gv-gv", }, i = { - ["c-j"] = [[lua require('copilot').accept()]], - [""] = "", + [""] = { 'copilot#Accept("")', expr = true }, + [""] = "", }, + t = { + ["A-l"] = "FTermClose" + } } for mode, mode_mappings in pairs(mappings) do for key, mapping in pairs(mode_mappings) do if type(mapping) == "function" then - keymap(mode, key, "lua " .. mapping() .. "<>", opts) + -- For direct Lua function calls; ensure your function returns a string command + keymap(mode, key, "lua " .. mapping() .. "", 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) elseif type(mapping) == "table" then + -- For mappings that have their options specified directly keymap(mode, key, mapping[1], mapping[2] or opts) else + -- For simple string command mappings keymap(mode, key, mapping, opts) end end diff --git a/lua/lsp.lua b/lua/lsp.lua index 8ab0d23..a133758 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -1,14 +1,5 @@ --- Set different settings for different languages' LSP --- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md --- How to use setup({}): https://github.com/neovim/nvim-lspconfig/wiki/Understanding-setup-%7B%7D --- - the settings table is sent to the LSP --- - on_attach: a lua callback function to run after LSP attaches to a given buffer local lspconfig = require('lspconfig') --- Customized on_attach function --- See `:help vim.diagnostic.*` for documentation on any of the below functions -local opts = { noremap = true, silent = true } - local mappings = { ['k'] = vim.diagnostic.open_float, ['[d'] = vim.diagnostic.goto_prev, diff --git a/lua/options.lua b/lua/options.lua index 1c53cc6..3a59061 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -5,7 +5,7 @@ local global = vim.g -- Hint: use `:h