From 2c815142218ddc90eb7002fa3720c73d60dccc4d Mon Sep 17 00:00:00 2001 From: Simon Lasbrugnas Date: Tue, 14 Nov 2023 13:44:10 +0100 Subject: [PATCH] feat: update plugin configurations and add new ones Update default configurations such as disabling netrw, setting 'isfname' option and better key mappings for several use cases including navigation, and deletion of buffers among others. Add new plugins including Comment.nvim for easier code commenting, nvim-tree for file exploration, gitsigns for git activity within nvim, and several color scheme plugins for better aesthetics. Also updated several existing plugins configurations, including telescope for file searching, trouble for diagnostics within nvim, and nvim-treesitter for better syntax highlighting. The key mappings have been improved to serve a variety of use cases, including , but not limited to, finding files, tab navigation, and various mappings for LSP functionalities. The aesthetics of the editor has been updated by adding a variety of color schemes to choose from, including fleet-theme-nvim, catppuccin, rose-pine, and toky onight.nvim Features like comment toggling with Comment.nvim, file tree viewing with nv im-tree and git activity per line with gitsigns.nvim have also been introduced . Some plugins like vim-bujo have also been removed as they no longer seem to be used in the configuration. The packer.lua file has also been edited to reflect these changes, with additions of plugins and the removal of vim-bujo. The lsp.lua file has been updated to include new commands that handles formatting , eslint auto-fixing and added mappings for signature help and type definitions . Some key plugin configuration files have been newly created, like comment.lua , gitsigns.lua, indent-blankline.lua, neoai.lua, nvim-tree.lua, which were not present before. Existing plugins configuration files like telescope.lua, trouble.lua, zenmode .lua have been updated for better usability. Finally, netrw, the default vim file explorer has been disabled as it has been replaced by the nvim-tree plugin. /!\ OPEN AI wrote that --- after/plugin/colors.lua | 2 +- after/plugin/comment.lua | 1 + after/plugin/gitsigns.lua | 50 +++++++++++++++++ after/plugin/indent-blankline.lua | 19 +++++++ after/plugin/lsp.lua | 31 ++++++++--- after/plugin/neoai.lua | 57 ++++++++++++++++++++ after/plugin/nvim-tree.lua | 6 +++ after/plugin/telescope.lua | 9 ++-- after/plugin/treesitter.lua | 5 +- after/plugin/trouble.lua | 6 +++ after/plugin/zenmode.lua | 2 - lua/default/packer.lua | 89 ++++++++++++++++++++----------- lua/default/remap.lua | 34 +++++++++--- lua/default/set.lua | 8 +-- 14 files changed, 262 insertions(+), 57 deletions(-) create mode 100644 after/plugin/comment.lua create mode 100644 after/plugin/gitsigns.lua create mode 100644 after/plugin/indent-blankline.lua create mode 100644 after/plugin/neoai.lua create mode 100644 after/plugin/nvim-tree.lua mode change 100644 => 100755 lua/default/remap.lua diff --git a/after/plugin/colors.lua b/after/plugin/colors.lua index 9dd60aa..41f2f42 100644 --- a/after/plugin/colors.lua +++ b/after/plugin/colors.lua @@ -1,5 +1,5 @@ function ColorMyPencils(color) - color = color or "kanagawa-dragon" + color = color or "fleet" vim.cmd.colorscheme(color) end diff --git a/after/plugin/comment.lua b/after/plugin/comment.lua new file mode 100644 index 0000000..a844323 --- /dev/null +++ b/after/plugin/comment.lua @@ -0,0 +1 @@ +require('Comment').setup() diff --git a/after/plugin/gitsigns.lua b/after/plugin/gitsigns.lua new file mode 100644 index 0000000..7785670 --- /dev/null +++ b/after/plugin/gitsigns.lua @@ -0,0 +1,50 @@ +require('gitsigns').setup{ + signs = { + add = { text = '▏' }, + change = { text = '▏' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + untracked = { text = '┆' }, + }, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then return ']c' end + vim.schedule(function() gs.next_hunk() end) + return '' + end, {expr=true}) + + map('n', '[c', function() + if vim.wo.diff then return '[c' end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, {expr=true}) + + -- Actions + map('n', 'hs', gs.stage_hunk) + map('n', 'hr', gs.reset_hunk) + map('v', 'hs', function() gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('v', 'hr', function() gs.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('n', 'hS', gs.stage_buffer) + map('n', 'hu', gs.undo_stage_hunk) + map('n', 'hR', gs.reset_buffer) + map('n', 'hp', gs.preview_hunk) + map('n', 'hb', function() gs.blame_line{full=true} end) + map('n', 'tb', gs.toggle_current_line_blame) + map('n', 'hd', gs.diffthis) + map('n', 'hD', function() gs.diffthis('~') end) + map('n', 'td', gs.toggle_deleted) + + -- Text object + map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') + end +} diff --git a/after/plugin/indent-blankline.lua b/after/plugin/indent-blankline.lua new file mode 100644 index 0000000..0d9597d --- /dev/null +++ b/after/plugin/indent-blankline.lua @@ -0,0 +1,19 @@ +require "ibl".setup { + scope = { + enabled = true, + char = "▏", + show_start = false, + show_end = false, + include = { + node_type = { + lua = { "table_constructor" }, + }, + }, + }, + indent = { + char = "▏", + }, + exclude = { + buftypes = { "terminal", "nofile" }, + }, +} diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index ee22540..65581b8 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -4,12 +4,12 @@ local home = vim.fn.expand('$HOME') -- Activate intelephense lspconfig.intelephense.setup { - cmd = { "intelephense", "--stdio" }, - settings = { - intelephense = { - licenceKeyPath = home..'/intelephense/license.txt' + cmd = { "intelephense", "--stdio" }, + settings = { + intelephense = { + licenceKeyPath = home .. '/intelephense/license.txt' + } } - } } lsp.preset("recommended") @@ -24,7 +24,7 @@ lsp.nvim_workspace() local cmp = require('cmp') -local cmp_select = {behavior = cmp.SelectBehavior.Select} +local cmp_select = { behavior = cmp.SelectBehavior.Select } local cmp_mappings = lsp.defaults.cmp_mappings({ [''] = cmp.mapping.select_prev_item(cmp_select), [''] = cmp.mapping.select_next_item(cmp_select), @@ -50,7 +50,21 @@ lsp.set_preferences({ }) lsp.on_attach(function(client, bufnr) - local opts = {buffer = bufnr, remap = false} + local opts = { buffer = bufnr, remap = false } + + -- Format on save + -- vim.api.nvim_create_autocmd("BufWritePost", { + -- callback = function() + -- vim.lsp.buf.format() + -- end + -- }) + + -- Eslint auto fix on save + vim.api.nvim_create_autocmd('BufWritePre', { + pattern = { '*.tsx', '*.ts', '*.jsx', '*.js', '*.vue', '*.cjs', '*.mjs', '*.json', '*.css', '*.scss', '*.less', '*.yml' }, + command = 'silent! EslintFixAll', + group = vim.api.nvim_create_augroup('EslintAutocmdsFormatting', {}), + }) vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) @@ -62,6 +76,8 @@ lsp.on_attach(function(client, bufnr) vim.keymap.set("n", "rr", function() vim.lsp.buf.references() end, opts) vim.keymap.set("n", "rn", function() vim.lsp.buf.rename() end, opts) vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "ls", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "D", function() vim.lsp.buf.type_definition() end, opts) end) lsp.setup() @@ -69,4 +85,3 @@ lsp.setup() vim.diagnostic.config({ virtual_text = true }) - diff --git a/after/plugin/neoai.lua b/after/plugin/neoai.lua new file mode 100644 index 0000000..ac2ae55 --- /dev/null +++ b/after/plugin/neoai.lua @@ -0,0 +1,57 @@ +require("neoai").setup({ + models = { + { + name = "openai", + model = "gpt-4", + params = nil, + }, + }, + open_ai = { + api_key = { + env = "OPENAI_API_KEY", + value = nil, + get = function() + local key = vim.fn.system("pass show openai/api_key") + key = string.gsub(key, "\n", "") + return key + end, + }, + }, + shortcuts = { + { + name = "textify", + key = "as", + desc = "fix text with AI", + use_context = true, + prompt = [[ + Please rewrite the text to make it more readable, clear, + concise, and fix any grammatical, punctuation, or spelling + errors + ]], + modes = { "v" }, + strip_function = nil, + }, + { + name = "gitcommit", + key = "ag", + desc = "generate git commit message", + use_context = false, + prompt = function() + return [[ + With specifications from conventionalcommits.org, + the commit message should be formatted as follows: + [optional scope]: + + [optional body] + + [optional footer(s)] + Using the following git diff generate a consise and + clear git commit message, with a short title summary + that is 75 characters or less. + ]] .. vim.fn.system("git diff --cached") + end, + modes = { "n" }, + strip_function = nil, + }, + }, +}) diff --git a/after/plugin/nvim-tree.lua b/after/plugin/nvim-tree.lua new file mode 100644 index 0000000..26fa3fc --- /dev/null +++ b/after/plugin/nvim-tree.lua @@ -0,0 +1,6 @@ +require("nvim-tree").setup({ + sort_by = "case_sensitive", + view = { width = 40, }, + renderer = { group_empty = true, }, + filters = { dotfiles = true, }, +}) diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua index 2c108b6..fe289fc 100644 --- a/after/plugin/telescope.lua +++ b/after/plugin/telescope.lua @@ -19,7 +19,10 @@ vim.keymap.set('n', 'pf', function() builtin.find_files({ no_ignore = true, hidden = true }) end) vim.keymap.set('n', '', custom_git_files, {}) -vim.keymap.set('n', 'ps', function() - builtin.grep_string({ search = vim.fn.input("Grep > ") }) -end) +vim.keymap.set('n', 'ps', function() builtin.live_grep() end) vim.keymap.set('n', 'vh', builtin.help_tags, {}) +vim.keymap.set('n', 'fa', function() builtin.find_files({ follow = true, no_ignore = true, hidden = true }) end) +vim.keymap.set('n', 'fb', function() builtin.buffers() end) +vim.keymap.set('n', 'cm', function() builtin.git_commits() end) +vim.keymap.set('n', 'gt', function() builtin.git_status() end) + diff --git a/after/plugin/treesitter.lua b/after/plugin/treesitter.lua index 487dd5b..4e5f70b 100644 --- a/after/plugin/treesitter.lua +++ b/after/plugin/treesitter.lua @@ -1,4 +1,7 @@ require'nvim-treesitter.configs'.setup { + indent = { + enable = true + }, -- A list of parser names, or "all" ensure_installed = { "vimdoc", "javascript", "typescript", "c", "lua", "rust" }, @@ -17,7 +20,7 @@ require'nvim-treesitter.configs'.setup { -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). -- Using this option may slow down your editor, and you may see some duplicate highlights. -- Instead of true it can also be a list of languages - additional_vim_regex_highlighting = { "php", "twig", "svelte" } + additional_vim_regex_highlighting = { "php", "twig" } }, } diff --git a/after/plugin/trouble.lua b/after/plugin/trouble.lua index cf1256a..740ca8f 100644 --- a/after/plugin/trouble.lua +++ b/after/plugin/trouble.lua @@ -1,3 +1,9 @@ vim.keymap.set("n", "xq", "TroubleToggle quickfix", {silent = true, noremap = true} ) +vim.keymap.set("n", "xd", "TroubleToggle document_diagnostics", + {silent = true, noremap = true} +) +vim.keymap.set("n", "xt", "TroubleToggle telescope", + {silent = true, noremap = true} +) diff --git a/after/plugin/zenmode.lua b/after/plugin/zenmode.lua index 753fbf8..b699f3e 100644 --- a/after/plugin/zenmode.lua +++ b/after/plugin/zenmode.lua @@ -10,7 +10,6 @@ vim.keymap.set("n", "zz", function() vim.wo.wrap = false vim.wo.number = true vim.wo.rnu = true - ColorMyPencils() end) @@ -26,5 +25,4 @@ vim.keymap.set("n", "zZ", function() vim.wo.number = false vim.wo.rnu = false vim.opt.colorcolumn = "0" - ColorMyPencils() end) diff --git a/lua/default/packer.lua b/lua/default/packer.lua index 87d312c..c65f9b3 100644 --- a/lua/default/packer.lua +++ b/lua/default/packer.lua @@ -10,15 +10,21 @@ return require("packer").startup(function(use) use "wsdjeg/vim-fetch" use { - "nvim-telescope/telescope.nvim", tag = "0.1.0", + "nvim-telescope/telescope.nvim", requires = { {"nvim-lua/plenary.nvim"} } } + use 'numToStr/Comment.nvim' + use("tpope/vim-surround") use("rebelot/kanagawa.nvim") + use("felipeagc/fleet-theme-nvim") + use { "catppuccin/nvim", as = "catppuccin" } + use({ 'rose-pine/neovim', as = 'rose-pine' }) + use("folke/tokyonight.nvim") - use("vuciv/vim-bujo") + use("lukas-reineke/indent-blankline.nvim") use({ "folke/trouble.nvim", @@ -29,6 +35,15 @@ return require("packer").startup(function(use) end }) + use { + 'nvim-tree/nvim-tree.lua', + requires = { + 'nvim-tree/nvim-web-devicons', + }, + } + + use("lewis6991/gitsigns.nvim") + use("ThePrimeagen/refactoring.nvim") use { @@ -36,39 +51,49 @@ return require("packer").startup(function(use) run = function() local ts_update = require("nvim-treesitter.install").update({ with_sync = true }) ts_update() - end,} - use("nvim-treesitter/playground") - use("mbbill/undotree") - use("tpope/vim-fugitive") - use("nvim-treesitter/nvim-treesitter-context"); + end + } - use { - "VonHeikemen/lsp-zero.nvim", - branch = 'v1.x', - requires = { - -- LSP Support - {"neovim/nvim-lspconfig"}, - {"williamboman/mason.nvim"}, - {"williamboman/mason-lspconfig.nvim"}, + use("nvim-treesitter/playground") + use("mbbill/undotree") + use("tpope/vim-fugitive") + use("nvim-treesitter/nvim-treesitter-context"); + use("jacoborus/tender.vim") - -- Autocompletion - {"hrsh7th/nvim-cmp"}, - {"hrsh7th/cmp-buffer"}, - {"hrsh7th/cmp-path"}, - {"saadparwaiz1/cmp_luasnip"}, - {"hrsh7th/cmp-nvim-lsp"}, - {"hrsh7th/cmp-nvim-lua"}, - - -- Snippets - {"L3MON4D3/LuaSnip"}, - {"rafamadriz/friendly-snippets"}, - } + use { + "Bryley/neoai.nvim", + requires = { + "MunifTanjim/nui.nvim", } + } + use { + "VonHeikemen/lsp-zero.nvim", + branch = 'v1.x', + requires = { + -- LSP Support + {"neovim/nvim-lspconfig"}, + {"williamboman/mason.nvim"}, + {"williamboman/mason-lspconfig.nvim"}, - use("folke/zen-mode.nvim") - use("github/copilot.vim") - use("eandrju/cellular-automaton.nvim") - use("laytan/cloak.nvim") + -- Autocompletion + {"hrsh7th/nvim-cmp"}, + {"hrsh7th/cmp-buffer"}, + {"hrsh7th/cmp-path"}, + {"saadparwaiz1/cmp_luasnip"}, + {"hrsh7th/cmp-nvim-lsp"}, + {"hrsh7th/cmp-nvim-lua"}, - end) + -- Snippets + {"L3MON4D3/LuaSnip"}, + {"rafamadriz/friendly-snippets"}, + -- Colors + {"folke/lsp-colors.nvim"}, + } + } + + use("folke/zen-mode.nvim") + use("github/copilot.vim") + use("eandrju/cellular-automaton.nvim") + use("laytan/cloak.nvim") +end) diff --git a/lua/default/remap.lua b/lua/default/remap.lua old mode 100644 new mode 100755 index 0b5d280..1d7b0bc --- a/lua/default/remap.lua +++ b/lua/default/remap.lua @@ -1,6 +1,5 @@ - vim.g.mapleader = " " -vim.keymap.set("n", "pv", vim.cmd.Ex) +vim.keymap.set("n", "e", ":NvimTreeFindFileToggle") vim.keymap.set("v", "J", ":m '>+1gv=gv") vim.keymap.set("v", "K", ":m '<-2gv=gv") @@ -27,10 +26,10 @@ vim.keymap.set("n", "Q", "") vim.keymap.set("n", "", "silent !tmux neww tmux-sessionizer") vim.keymap.set("n", "f", vim.lsp.buf.format) -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") +vim.keymap.set("n", "", "cprevzz") +vim.keymap.set("n", "j", "lnextzz") +vim.keymap.set("n", "k", "lprevzz") vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) vim.keymap.set("n", "x", "!chmod +x %", { silent = true }) @@ -39,6 +38,29 @@ vim.keymap.set("n", "", function() vim.cmd("so") end) +-- Keybindings for navigating tabs +vim.keymap.set("n", ".", function() + vim.cmd("tabn") +end, {}) +vim.keymap.set("n", "", function() + vim.cmd("tabn") +end, {}) +vim.keymap.set("n", ",", function() + vim.cmd("tabp") +end, {}) +vim.keymap.set("n", "tc", function() + vim.cmd("tabc") +end, {}) +vim.keymap.set("n", "tt", function() + vim.cmd("tabnew") +end, {}) +vim.keymap.set("n", "<", function() + vim.cmd("tabfirst") +end, {}) +vim.keymap.set("n", ">", function() + vim.cmd("tablast") +end, {}) + -- Keybinding for deleting the current buffer using :bd vim.keymap.set("n", "bd", function() vim.cmd("bd") diff --git a/lua/default/set.lua b/lua/default/set.lua index 73d2ef0..c7f4279 100644 --- a/lua/default/set.lua +++ b/lua/default/set.lua @@ -1,3 +1,7 @@ +-- disable netrw +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + vim.opt.nu = true vim.opt.relativenumber = true @@ -26,7 +30,3 @@ vim.opt.signcolumn = "yes" vim.opt.isfname:append("@-@") vim.opt.updatetime = 50 - --- vim-bujo settings -vim.api.nvim_set_var('bujo#todo_file_path', os.getenv('HOME') .. '/.bujo') -vim.api.nvim_set_var('bujo#window_width', 60)