From 14bca306959e4f090dfe4079a1ae073c559c2cf3 Mon Sep 17 00:00:00 2001 From: Pratik Tripathy Date: Sun, 24 Dec 2023 23:39:58 +0530 Subject: [PATCH] NVIM with Lazy.vim Package Manager - Added the basic setting for functional LSP. - Split configurations into multiple files suitable for Lazy usage. --- .gitignore | 5 +- common/.config/nvim/autoload | 1 - common/.config/nvim/init.lua | 31 ++++++++ common/.config/nvim/lua/plugins.lua | 15 ++++ .../.config/nvim/lua/plugins/codinghelp.lua | 73 +++++++++++++++++++ .../.config/nvim/lua/plugins/colorthemes.lua | 30 ++++++++ common/.config/nvim/lua/plugins/lualine.lua | 10 +++ common/.config/nvim/lua/plugins/neo-tree.lua | 13 ++++ common/.config/nvim/lua/plugins/telescope.lua | 27 +++++++ .../nvim/lua/plugins/todo-comments.lua | 20 +++++ .../.config/nvim/{init.vim => vim-sync.vim} | 13 +--- common/.vim/configs.vim | 1 + common/.vim/key_maps.vim | 6 +- 13 files changed, 228 insertions(+), 17 deletions(-) delete mode 120000 common/.config/nvim/autoload create mode 100644 common/.config/nvim/init.lua create mode 100644 common/.config/nvim/lua/plugins.lua create mode 100644 common/.config/nvim/lua/plugins/codinghelp.lua create mode 100644 common/.config/nvim/lua/plugins/colorthemes.lua create mode 100644 common/.config/nvim/lua/plugins/lualine.lua create mode 100644 common/.config/nvim/lua/plugins/neo-tree.lua create mode 100644 common/.config/nvim/lua/plugins/telescope.lua create mode 100644 common/.config/nvim/lua/plugins/todo-comments.lua rename common/.config/nvim/{init.vim => vim-sync.vim} (59%) diff --git a/.gitignore b/.gitignore index 525a9dc..9f2ae21 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,9 @@ Temporary Items # Vim Artifacts *.swp +# NVIM Artifacts +*.luarc.json + resharper-host/ tasks/ @@ -85,4 +88,4 @@ node_modules/* *.jsc **/contents/images **/contents/fonts -*kpluginindex.json \ No newline at end of file +*kpluginindex.json diff --git a/common/.config/nvim/autoload b/common/.config/nvim/autoload deleted file mode 120000 index 568e63f..0000000 --- a/common/.config/nvim/autoload +++ /dev/null @@ -1 +0,0 @@ -../../.vim/autoload \ No newline at end of file diff --git a/common/.config/nvim/init.lua b/common/.config/nvim/init.lua new file mode 100644 index 0000000..30d9809 --- /dev/null +++ b/common/.config/nvim/init.lua @@ -0,0 +1,31 @@ +-- TODO: Todo-Comments: Highlight TODOs +-- TODO: Neo-Tree: reduce size, hidden visible by default, set vcs root at pwd+cwd +-- TODO: Telescope: open in a new window -> vertial & horizontal +-- TODO: LSPConfig: Standardize keymaps to d[x] +-- TODO: Note what exactly Treesitter does??? + +-- Loads the system's Vim configs: keeps the VIM & NVim configs in sync +local vimrc = vim.fn.stdpath("config") .. "/vim-sync.vim" +if vim.loop.fs_stat(vimrc) then + vim.cmd("source " .. vimrc) +end + +-- Setup Lazy.nvim package manager +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) +require("lazy").setup("plugins", { + change_detection = { + enabled = true, + notify = false + } +}) diff --git a/common/.config/nvim/lua/plugins.lua b/common/.config/nvim/lua/plugins.lua new file mode 100644 index 0000000..d85acf5 --- /dev/null +++ b/common/.config/nvim/lua/plugins.lua @@ -0,0 +1,15 @@ +-- Keeps the plugin list that Lazy uses at one place +return { + -- From VIM + { "tpope/vim-fugitive" }, + { "tpope/vim-surround" }, + { "tpope/vim-repeat" }, + { "tpope/vim-commentary" }, + { "tpope/vim-sensible" }, + { "rstacruz/vim-closer" }, + { "machakann/vim-highlightedyank" }, + { "airblade/vim-gitgutter" }, + { "easymotion/vim-easymotion" }, + { "preservim/nerdtree" }, + -- { 'itchyny/lightline.vim' }, +} diff --git a/common/.config/nvim/lua/plugins/codinghelp.lua b/common/.config/nvim/lua/plugins/codinghelp.lua new file mode 100644 index 0000000..e77ad0c --- /dev/null +++ b/common/.config/nvim/lua/plugins/codinghelp.lua @@ -0,0 +1,73 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + local tree_config = require("nvim-treesitter.configs") + tree_config.setup({ + ensure_installed = { "lua", "vim", "vimdoc", "bash", "c_sharp", "css", "dockerfile", "git_config", "gitignore", "html", "http", "ini", "json", "proto", "python", "rust", "sql", "toml", "tsx", "typescript" , "javascript" }, + highlight = { enable = true }, + indent = { enable = true }, + }) + end + }, + + -- LSP Configuration + { + -- Provides :Mason command which installs Language Servers + "williamboman/mason.nvim", + config = function() + require("mason").setup() + end + }, + { + -- Helps to auto install Language Servers by specifying them + "williamboman/mason-lspconfig.nvim", + config = function() + require("mason-lspconfig").setup({ + ensure_installed = { "lua_ls", "bashls", "cssls", "dockerls", "emmet_ls", "jsonls", "tsserver", "marksman", "pyre", "rust_analyzer", "sqlls", "taplo" } + }) + end + }, + { + "neovim/nvim-lspconfig", + config = function() + -- Hook up NVIM with the above installed Language Servers + local lspconfig = require("lspconfig") + lspconfig.lua_ls.setup({}) + lspconfig.bashls.setup({}) + lspconfig.cssls.setup({}) + lspconfig.dockerls.setup({}) + lspconfig.emmet_ls.setup({}) + lspconfig.jsonls.setup({}) + lspconfig.tsserver.setup({}) + lspconfig.marksman.setup({}) + lspconfig.pyre.setup({}) + lspconfig.rust_analyzer.setup({}) + lspconfig.sqlls.setup({}) + lspconfig.taplo.setup({}) + + -- LSP Keybindings + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next) + vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, {}) + vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, {}) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {}) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, {}) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, {}) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, {}) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, {}) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, {}) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, {}) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, {}) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, {}) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, {}) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, {}) + end + } +} diff --git a/common/.config/nvim/lua/plugins/colorthemes.lua b/common/.config/nvim/lua/plugins/colorthemes.lua new file mode 100644 index 0000000..f5b440c --- /dev/null +++ b/common/.config/nvim/lua/plugins/colorthemes.lua @@ -0,0 +1,30 @@ +return { + { + "rebelot/kanagawa.nvim", + name = "kanagawa", + priority = 1000, + lazy = false, + config = function() + vim.cmd.colorscheme "kanagawa-wave" + end + }, + { + "catppuccin/nvim", + name = "catppuccin", + priority = 1000, + -- config = function() + -- show_end_of_buffer = true, + -- integrations = { + -- cmp = true, + -- gitsigns = true, + -- nvimtree = true, + -- }, + -- vim.cmd.colorscheme "catppuccin-macchiato", + -- end + }, + { + "rose-pine/neovim", + name = "rose-pine", + priority = 1000, + }, +} diff --git a/common/.config/nvim/lua/plugins/lualine.lua b/common/.config/nvim/lua/plugins/lualine.lua new file mode 100644 index 0000000..a4cf538 --- /dev/null +++ b/common/.config/nvim/lua/plugins/lualine.lua @@ -0,0 +1,10 @@ +return { + "nvim-lualine/lualine.nvim", + config = function() + require("lualine").setup({ + options = { + theme = "powerline_dark" + } + }) + end +} diff --git a/common/.config/nvim/lua/plugins/neo-tree.lua b/common/.config/nvim/lua/plugins/neo-tree.lua new file mode 100644 index 0000000..9af12fe --- /dev/null +++ b/common/.config/nvim/lua/plugins/neo-tree.lua @@ -0,0 +1,13 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", + "MunifTanjim/nui.nvim", + }, + config = function() + -- Keymaps for Neotree + vim.keymap.set("n", "n", ":lcd %:h :Neotree filesystem reveal left") + end +} diff --git a/common/.config/nvim/lua/plugins/telescope.lua b/common/.config/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..632a4fd --- /dev/null +++ b/common/.config/nvim/lua/plugins/telescope.lua @@ -0,0 +1,27 @@ +return { + { + 'nvim-telescope/telescope.nvim', tag = '0.1.5', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + -- Keymaps for Telescope + local builtin = require("telescope.builtin") + vim.keymap.set("n", "ff", builtin.find_files, {}) + vim.keymap.set("n", "fg", builtin.live_grep, {}) + vim.keymap.set("n", "fb", builtin.buffers, {}) + end + }, + { + "nvim-telescope/telescope-ui-select.nvim", + config = function() + require("telescope").setup({ + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown{ + } + } + } + }) + require("telescope").load_extension("ui-select") + end + } +} diff --git a/common/.config/nvim/lua/plugins/todo-comments.lua b/common/.config/nvim/lua/plugins/todo-comments.lua new file mode 100644 index 0000000..c4e8a08 --- /dev/null +++ b/common/.config/nvim/lua/plugins/todo-comments.lua @@ -0,0 +1,20 @@ +return { + "folke/todo-comments.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + config = function() + vim.keymap.set("n", "]t", function() + require("todo-comments").jump_next( + { keywords = { "ERROR", "WARNING", "TODO" }} + ) + end, + { desc = "Next todo comment"} + ) + vim.keymap.set("n", "[t", function() + require("todo-comments").jump_prev( + { keywords = { "ERROR", "WARNING", "TODO" }} + ) + end, + { desc = "Previous todo comment"} + ) + end +} diff --git a/common/.config/nvim/init.vim b/common/.config/nvim/vim-sync.vim similarity index 59% rename from common/.config/nvim/init.vim rename to common/.config/nvim/vim-sync.vim index 6a4b1fd..5f48d1b 100644 --- a/common/.config/nvim/init.vim +++ b/common/.config/nvim/vim-sync.vim @@ -1,14 +1,11 @@ """""""""""""""""""""""""""""""""""""" " -" Get source common configs from VIM +" Source common configs from VIM " """""""""""""""""""""""""""""""""""""" let $VIMDIR="$HOME/.vim" let $NVIMDIR="$HOME/.config/nvim" -" Load plugins -source $VIMDIR/plugins.vim - " Load VIM Configurations source $VIMDIR/configs.vim @@ -18,11 +15,3 @@ source $VIMDIR/key_maps.vim " Save session files to $HOME/.vim/session directory let g:session_dir="$VIMDIR/session" -"""""""""""""""""""""""""""""""" -" -" LOOKS -" -"""""""""""""""""""""""""""""""" -let g:lightline = { 'colorscheme': 'deepspace' } -colorscheme deep-space - diff --git a/common/.vim/configs.vim b/common/.vim/configs.vim index 462817d..848514d 100644 --- a/common/.vim/configs.vim +++ b/common/.vim/configs.vim @@ -8,6 +8,7 @@ set shiftwidth=4 tabstop=4 softtabstop=4 expandtab set autoindent smartindent syntax on " syntax highlighting. +set cursorline " Hightlight cursor line set showmatch " Highlight matching braces set ls=2 " Show a status line set wrap " Wrap text diff --git a/common/.vim/key_maps.vim b/common/.vim/key_maps.vim index 7d54ba3..9893727 100644 --- a/common/.vim/key_maps.vim +++ b/common/.vim/key_maps.vim @@ -36,6 +36,9 @@ nnoremap / :call clearmatches():noh " Make space-bar the leader-key let mapleader = " " +" Changes the pwd to the opened file's directory +nnoremap cd :lcd %:h + " Map easymotion Plugin to j map j (easymotion-s) @@ -45,6 +48,3 @@ nnoremap e :lcd %:h :NERDTreeToggleVCS let g:NERDTreeShowHidden = 1 let g:NERDTreeWinSize = 20 -" Changes the pwd to the opened file's directory -nnoremap cd :lcd %:h -