From aee290dcf96dab9ee2f891a92d0761aa9bfedcd3 Mon Sep 17 00:00:00 2001 From: David Ibia Date: Wed, 3 Jan 2024 17:54:20 +0100 Subject: [PATCH] feat: add support for Jedi-Vim plugin - Add configuration for Jedi-Vim plugin in `lua/absolute/plugins/jedi.lua` - Create `lua/absolute/after/jedi.lua` to set Jedi-Vim mappings and options fix: fix lualine theme and add custom section - Update `lua/absolute/after/lualine.lua` to fix the lualine theme configuration - Add a custom section to display the Poetv status line in lualine feat: add keybindings for Poetv plugin - Add keybindings for activating and deactivating virtualenv in `lua/absolute/after/poet-v.lua` fix: fix remap keybindings - Update `lua/absolute/remap.lua` to fix and improve remap keybindings feat: add alternate escape keybinding - Add keybinding to use as an alternate escape key in insert mode fix: disable Q keybinding - Disable the Q keybinding to prevent accidentally entering Ex mode feat: add keybinding for formatting document with LSP Formatter - Add keybinding to format the document using the LSP Formatter feat: add keybindings for navigation quick fixes - Add keybindings for navigating through quick fixes in the location list and the quickfix list feat: add keybinding for regex replace - Add keybinding to perform a regex replace in the entire file feat: add keybinding for sourcing file - Add keybinding to source the current file feat: add keybinding for toggling TMUX pane - Add keybinding to toggle the TMUX pane using MaximizerToggle command --- lazy-lock.json | 7 +-- lua/absolute/after/jedi.lua | 10 ++++ lua/absolute/after/lualine.lua | 33 +++++++++++++ lua/absolute/after/poet-v.lua | 13 +++++ lua/absolute/core/init.lua | 1 - lua/absolute/plugins/jedi.lua | 6 +++ lua/absolute/remap.lua | 87 +++++++++++++++++++++++----------- 7 files changed, 125 insertions(+), 32 deletions(-) create mode 100644 lua/absolute/after/jedi.lua create mode 100644 lua/absolute/plugins/jedi.lua diff --git a/lazy-lock.json b/lazy-lock.json index 0b1d19b..6cc04c1 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -13,6 +13,7 @@ "friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" }, "gitignore.nvim": { "branch": "master", "commit": "e0e0c511595681ef826a91a9e8449e86049406a0" }, "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, + "jedi-vim": { "branch": "master", "commit": "9bd79ee41ac59a33f5890fa50b6d6a446fcc38c7" }, "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, "lspkind.nvim": { "branch": "master", "commit": "7f26cf5e27e2bd910ce0ea00c514da2bf97423b8" }, "lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" }, @@ -24,12 +25,12 @@ "nvim-cmp": { "branch": "main", "commit": "538e37ba87284942c1d76ed38dd497e54e65b891" }, "nvim-dap": { "branch": "master", "commit": "f0dca670fa059eb89dda8869a6310c804241345c" }, "nvim-dap-python": { "branch": "master", "commit": "091e4ae00a12085f9ed4200a3cd04af7179b8a23" }, - "nvim-dap-ui": { "branch": "master", "commit": "34160a7ce6072ef332f350ae1d4a6a501daf0159" }, + "nvim-dap-ui": { "branch": "master", "commit": "947660daced01c3eb673e3dc9527c988e42fe4cc" }, "nvim-lsp-file-operations": { "branch": "master", "commit": "8e7223e138590c1bd9d86d3de810e65939d8b12f" }, "nvim-lspconfig": { "branch": "master", "commit": "ce0e625df61be77abe1340fbc9afe9ad39b31dd8" }, "nvim-tree.lua": { "branch": "master", "commit": "f1b3e6a7eb92da492bd693257367d9256839ed3d" }, - "nvim-treesitter": { "branch": "master", "commit": "65ef62092ef997d2ecf68ede01a0afbda17808c3" }, - "nvim-web-devicons": { "branch": "master", "commit": "cff25ce621e6d15fae0b0bfe38c00be50ce38468" }, + "nvim-treesitter": { "branch": "master", "commit": "3ef514b10b9557e3905b9817ca632e7506dd384a" }, + "nvim-web-devicons": { "branch": "master", "commit": "3e24abe1ae66532135cec911562f553fe247cb56" }, "nvim_lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" }, "plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" }, diff --git a/lua/absolute/after/jedi.lua b/lua/absolute/after/jedi.lua new file mode 100644 index 0000000..4f1e263 --- /dev/null +++ b/lua/absolute/after/jedi.lua @@ -0,0 +1,10 @@ +vim.g["jedi#goto_command"] = "" -- "d" +vim.g["jedi#goto_assignments_command"] = "gD" +vim.g["jedi#goto_stubs_command"] = "" -- "s" +vim.g["jedi#goto_definitions_command"] = "gd" +vim.g["jedi#documentation_command"] = "K" +vim.g["jedi#usages_command"] = "n" +vim.g["jedi#completions_command"] = "" +vim.g["jedi#rename_command"] = "rn" +vim.g["jedi#rename_command_keep_name"] = "" -- "R" + diff --git a/lua/absolute/after/lualine.lua b/lua/absolute/after/lualine.lua index b50db42..1587a2a 100644 --- a/lua/absolute/after/lualine.lua +++ b/lua/absolute/after/lualine.lua @@ -45,6 +45,34 @@ local my_lualine_theme = { }, } + +function GetPoetvStatusLine() + -- Get the poetv statusline + -- If poetv is not active, return empty string + + if IsPoetvActive() then + local poetv_name = vim.g.poetv_name + local poetv_statusline_symbol = vim.g.poetv_statusline_symbol + + local result = string.sub(poetv_name, 1, 20) .. " " .. poetv_statusline_symbol + + return result + else + return "" + end +end + +function IsPoetvActive() + -- Check if vim.g.poetv_name exists + -- If it does, then poetv is active + + if vim.g.poetv_name ~= nil then + return true + else + return false + end +end + -- configure lualine with modified theme lualine.setup({ options = { @@ -52,6 +80,11 @@ lualine.setup({ }, sections = { lualine_x = { + { + GetPoetvStatusLine, + cond = IsPoetvActive, + color = { fg = "#ff9e64" }, + }, { lazy_status.updates, cond = lazy_status.has_updates, diff --git a/lua/absolute/after/poet-v.lua b/lua/absolute/after/poet-v.lua index e2582f3..e0a0317 100644 --- a/lua/absolute/after/poet-v.lua +++ b/lua/absolute/after/poet-v.lua @@ -2,3 +2,16 @@ vim.g.poetv_executables = { "poetry", "pipenv" } vim.g.poetv_auto_activate = 1 vim.g.poetv_set_environment = 1 vim.g.poetv_statusline_symbol = "🐍" + + +-- Keybindings + +local opts = { noremap = true, silent = true } + +-- Poetv: Activate Virtualenv +opts.desc = "Poetv: Activate virtualenv" +vim.keymap.set("n", "pva", "PoetvActivate", opts) + +-- Poetv: Deactivate Virtualenv +opts.desc = "Poetv: Deactivate virtualenv" +vim.keymap.set("n", "pvd", "PoetvDeactivate", opts) diff --git a/lua/absolute/core/init.lua b/lua/absolute/core/init.lua index e6261f9..b3a10e8 100644 --- a/lua/absolute/core/init.lua +++ b/lua/absolute/core/init.lua @@ -31,4 +31,3 @@ vim.opt.updatetime = 50 vim.opt.colorcolumn = "" vim.g.mapleader = " " -vim.g.maplocalleader = "\\" diff --git a/lua/absolute/plugins/jedi.lua b/lua/absolute/plugins/jedi.lua new file mode 100644 index 0000000..55f8899 --- /dev/null +++ b/lua/absolute/plugins/jedi.lua @@ -0,0 +1,6 @@ +return { + "davidhalter/jedi-vim", + config = function() + require("absolute.after.jedi") + end +} diff --git a/lua/absolute/remap.lua b/lua/absolute/remap.lua index f61cfe4..4b77d6e 100644 --- a/lua/absolute/remap.lua +++ b/lua/absolute/remap.lua @@ -1,59 +1,90 @@ -vim.keymap.set("n", "\\", "NvimTreeToggle") -- toggle file explorer +local opts = { noremap = true, silent = true } + +opts.desc = "Toggle File Explorer" +vim.keymap.set("n", "\\", "NvimTreeToggle", opts) -- toggle file explorer -- Move selected line / block of text in visual mode up -vim.keymap.set("v", "J", ":m '>+1gv=gv") +opts.desc = "Move selected line / block of text in visual mode up" +vim.keymap.set("v", "J", ":m '>+1gv=gv", opts) -- Move selected line / block of text in visual mode down -vim.keymap.set("v", "K", ":m '<-2gv=gv") +opts.desc = "Move selected line / block of text in visual mode down" +vim.keymap.set("v", "K", ":m '<-2gv=gv", opts) -vim.keymap.set("n", "J", "mzJ`z") +-- Join current line with the line below it +opts.desc = "Join current line with the line below it" +vim.keymap.set("n", "J", "mzJ`z", opts) --- Move half page down -vim.keymap.set("n", "", "zz") + +-- Move half page down +opts.desc = "Move half page down" +vim.keymap.set("n", "", "zz", opts) -- Move half page up -vim.keymap.set("n", "", "zz") +opts.desc = "Move half page up" +vim.keymap.set("n", "", "zz", opts) + +-- Navigate to next search result, center screen and expand folded text +opts.desc = "Navigate to next search result, center screen and expand folded text" +vim.keymap.set("n", "n", "nzzzv", opts) + +-- Navigate to previous search result, center screen and expand folded text, +opts.desc = "Navigate to previous search result, center screen and expand folded text" +vim.keymap.set("n", "N", "Nzzzv", opts) + +-- Delete selected text and paste from register +opts.desc = "Delete selected text and paste from register" +vim.keymap.set("x", "p", [["_dP]], opts) + +-- Copy selected text into system clipboard +opts.desc = "Copy selected text into system clipboard" +vim.keymap.set({ "n", "v" }, "y", [["+y]], opts) + +-- Copy current line into system clipboard +opts.desc = "Copy current line into system clipboard" +vim.keymap.set("n", "Y", [["+Y]], opts) -vim.keymap.set("n", "n", "nzzzv") -vim.keymap.set("n", "N", "Nzzzv") - -vim.keymap.set("x", "p", [["_dP]]) - -vim.keymap.set({ "n", "v" }, "y", [["+y]]) -vim.keymap.set("n", "Y", [["+Y]]) - -vim.keymap.set({ "n", "v" }, "d", [["_d]]) +-- Delete (blackhole) +opts.desc = "Delete current line (blackhole)" +vim.keymap.set({ "n", "v" }, "d", [["_d]], opts) -- Alternate Escape (Easy to Reach) -vim.keymap.set("i", "", "") +opts.desc = "Alternate Escape (Easy to Reach)" +vim.keymap.set("i", "", "", opts) -- Disable Q - Nothing Good Ever Happens -vim.keymap.set("n", "Q", "") +-- Q is normally used to enable Ex mode. We dont want that +opts.desc = "Disable Q - Nothing Good Ever Happens" +vim.keymap.set("n", "Q", "", opts) -- Format document with LSP Formatter -vim.keymap.set("n", "f", vim.lsp.buf.format) +opts.desc = "Format document with LSP Formatter" +vim.keymap.set("n", "f", vim.lsp.buf.format, opts) -- Navigation Quick Fixes - -vim.keymap.set("n", "", "cnextzz") -vim.keymap.set("n", "", "cprevzz") -vim.keymap.set("n", "k", "lnextzz") -vim.keymap.set("n", "j", "lprevzz") - +-- +-- vim.keymap.set("n", "", "cnextzz", opts) +-- vim.keymap.set("n", "", "cprevzz", opts) +-- vim.keymap.set("n", "k", "lnextzz", opts) +-- vim.keymap.set("n", "j", "lprevzz", opts) +-- -- Search Regex Keymap -vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) +opts.desc = "Regex Replace" +vim.keymap.set("n", "s", [[:%s/\<\>//gI]], opts) -- Source File Keymap +opts.desc = "Source File" vim.keymap.set("n", "", function() vim.cmd("so") -end) +end, opts) -- Manage VIM Maximizer -vim.keymap.set("n", "sm", "MaximizerToggle") +opts.desc = "Toggle TMUX Pane" +vim.keymap.set("n", "sm", "MaximizerToggle", opts)