diff --git a/README.md b/README.md index a8cc20f..9467695 100644 --- a/README.md +++ b/README.md @@ -2,30 +2,46 @@ A NICE configuration for NeoVim with a lot of features and plugins to make your ## Installation +### Prerequisites + +#### Automated setup + Find a Release version and download the zip file. Extract the zip file in your desired location, - in the root directory of the extracted files, run `./install.sh` - sit back and relax as the script installs all the necessary plugins and configurations - run `> tmux` and run `> nvim` in your terminal to open NeoVim in a tmux session and start using the IDE - -### Installation of Neovim plugins - - run `:PackerInstall` in NeoVim to install all the plugins -- install your favourite Coc.nvim extensions e.g. `CocInstall coc-eslint`, `CocInstall coc-prettier` etc - choose your favourite theme by running `:colorscheme ` -### Setting up terminal devicons +#### Setting up terminal devicons -This will enable Vim/NeoVim to display nerd icons e.g. File Extension icons on `nvim-tree` or NERDTree etc. +This will enable Vim/NeoVim to display nerd icons e.g. File Extension icons in the File Explorer - Download and install a [patched Nerd Font](https://github.com/ryanoasis/nerd-fonts) - such as [Hack Nerd Font](https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Hack.zip) - ensure that the font installed has nerd devicons - You can use Font Book if using MacOS to check out the installed font - Open you terminal emulator e.g. ITerm and set the Font Type to the patched font -### Useful keyboard mappings/shortcuts to use the IDE +#### Configuring a mergetool for merge conflicts + +Add the following to your `~/.gitconfig` file +This will open a 3-way merge tool in NeoVim when you have merge conflicts. e.g. when opening a conflicted file within lazygit `:LazyGit` UI + +``` +[core] + editor = nvim +[merge] + tool = nvim +[mergetool "nvim"] + cmd = nvim -c "DiffviewOpen" +[mergetool] + prompt = false +``` + +## Useful keyboard mappings/shortcuts and useful commands to use the IDE -#### Normal mode +### Normal mode - `` - Toggle File Explorer - `tr` - Toggle right panel @@ -44,7 +60,14 @@ This will enable Vim/NeoVim to display nerd icons e.g. File Extension icons on ` - `gq` - Quit current buffer - `o` - Quit all tabs except current - `o` - Quit all window in current tab except current window -- `c` - Searches Coc.nvim commands with `:CocCommand` + +### Commands + +- `:LazyGit` - open embedded lazygit +- `:G` - open vim-fugitive git status window. A git repo alternatively to lazygit +- `:colorscheme ` - choose your favourite theme +- `:CtrlP ` - CtrlP commands e.g. search MRU files +- `:` - see all available commands ## Screenshots (carbonfox colorscheme) @@ -55,7 +78,16 @@ Embedded lazygit view Screenshot 2021-11-11 at 19 09 49 -## Other tips +## Advanced + +Once you get comfortable and excited, let's go, + +#### Working with Language Servers, Debuggers and Linters + +- Run `:Mason` and find and install some LSP extensions and Linters you might want + - Configure the LSP and Linters with lspconfig +- Find Coc.nvim extensions that you might like e.g. `CocInstall coc-eslint` +- Learn to use nvim-dap ### Setting up italic text in iTerm2 diff --git a/install.sh b/install.sh index a144c75..6b782f6 100755 --- a/install.sh +++ b/install.sh @@ -28,7 +28,13 @@ brew install --quiet neovim echo "${green}󰄸 Done ${textreset} - Installed neovim" # neovim config dir echo "${cyan} Linking nvim configuration ${textreset}" -ln -sf $(pwd)/v2/nvim ~/.config/nvim + +NVIM_DIR=~/.config/nvim +if [ -d $NVIM_DIR ]; then + echo "${yellow} nvim config already exists. Removing.${textreset}" + rm -rf $NVIM_DIR +fi +ln -sf $(pwd)/v2/nvim $NVIM_DIR echo "${green}󰄸 Done ${textreset} - Linked nvim config to ~/.config/nvim\n" diff --git a/v2/nvim/init.lua b/v2/nvim/init.lua index 6f1e775..120a390 100644 --- a/v2/nvim/init.lua +++ b/v2/nvim/init.lua @@ -15,7 +15,7 @@ require("johnmutuma.plugins.nvim-tree") -- - LSP require("johnmutuma.plugins.lsp.mason") -require("johnmutuma.plugins.lsp.lspconfig") +-- require("johnmutuma.plugins.lsp.lspconfig") require("johnmutuma.plugins.lsp.coc-nvim") require("johnmutuma.plugins.lsp.lspsaga") require("johnmutuma.plugins.lsp.lsp-lens") diff --git a/v2/nvim/lua/johnmutuma/plugins/glance.lua b/v2/nvim/lua/johnmutuma/plugins/glance.lua index 84773b7..9a0c67f 100644 --- a/v2/nvim/lua/johnmutuma/plugins/glance.lua +++ b/v2/nvim/lua/johnmutuma/plugins/glance.lua @@ -54,5 +54,6 @@ local colorscheme_augroup = vim.api.nvim_create_augroup("colorschemechange", { c vim.api.nvim_create_autocmd({ "ColorScheme" }, { group = colorscheme_augroup, callback = setHiglightOverrides, + -- command = ":lua setHiglightOverrides()", -- pattern = {"*.adoc", "*.md", "*.tex"}, }) diff --git a/v2/nvim/lua/johnmutuma/plugins/lsp/lspconfig.lua b/v2/nvim/lua/johnmutuma/plugins/lsp/lspconfig.lua deleted file mode 100644 index 38e19ee..0000000 --- a/v2/nvim/lua/johnmutuma/plugins/lsp/lspconfig.lua +++ /dev/null @@ -1,134 +0,0 @@ -local lspconfig_ok, lspconfig = pcall(require, "lspconfig") -local typescript_ok, typescript = pcall(require, "typescript") -local cmp_nvim_lsp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") - --- vim.api.nvim_create_autocmd("LspAttach", { --- callback = function(args) --- local client = vim.lsp.get_client_by_id(args.data.client_id) --- client.server_capabilities.semanticTokensProvider = nil --- end, --- }) - -local setup_lsp = function(on_attach) - local capabilities = cmp_nvim_lsp.default_capabilities() - -- - -- configure the Language servers - -- lspconfig["eslint"].setup({ - -- capabilities = capabilities, - -- on_attach = on_attach, - -- }) - - lspconfig["html"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - typescript.setup({ - server = { - capabilities = capabilities, - on_attach = on_attach, - }, - }) - - lspconfig["ts_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - lspconfig["cssls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - lspconfig["gopls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { - gopls = { - analyses = { - unusedparams = true, - }, - staticcheck = true, - gofumpt = true, - }, - }, - }) - - -- lspconfig["jsonls"].setup({ -- preferring coc-json for workspace settings - -- capabilities = capabilities, - -- on_attach = on_attach, - -- }) - - lspconfig["lua_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - }, - }) -end - -if not lspconfig_ok then - print("lspconfig could not be loaded") - return -end - -if not typescript_ok then - print("jose-elias-alvarez/typescript could not be loaded") - return -end - -if not cmp_nvim_lsp_ok then - print("cmp_nvim_lsp could not be loaded") - return -end - -local keymap = vim.keymap -local on_attach = function(client, bufnr) - -- some language servers crash on semantic tokens when previewing files quickly e.g. Glance previews - -- disabling sematic tokens - hihglighting for now will be provided by nvim-treesitter - -- client.server_capabilities.semanticTokensProvider = nil - - local opts = { noremap = true, buffer = bufnr, silent = true } - -- LSP key bindings - keymap.set("n", "gR", "Glance references", opts) - -- keymap.set("n", "gR", "Lspsaga finder", opts) - -- keymap.set("n", "gd", "Lspsaga peek_definition", opts) - keymap.set("n", "gd", "Glance definitions", opts) - keymap.set("n", "gi", "Glance implementations") - keymap.set("n", "gT", "Glance type_definitions") - keymap.set("n", "g>", "Lspsaga outgoing_calls") - keymap.set("n", "g<", "Lspsaga incoming_calls") - keymap.set("n", "gD", vim.lsp.buf.declaration, opts) - -- keymap.set("n", "gi", vim.lsp.buf.implementation, opts) - -- keymap.set("n", "gr", vim.lsp.buf.references, opts) - keymap.set("n", "ca", "Lspsaga code_action", opts) - keymap.set("n", "rn", "Lspsaga rename", opts) - keymap.set("n", "]e", "Lspsaga diagnostic_jump_next", opts) - keymap.set("n", "[e", "Lspsaga diagnostic_jump_previous", opts) - keymap.set("n", "D", "Lspsaga show_buf_diagnostics", opts) - keymap.set("n", "d", "Lspsaga show_line_diagnostics", opts) - keymap.set("n", "wd", "Lspsaga show_workspace_diagnostics", opts) - keymap.set("n", "K", "Lspsaga hover_doc", opts) - - if client.name == "ts_ls" then - keymap.set("n", "rf", "TypescriptRenameFile", opts) - end -end - -setup_lsp(on_attach) diff --git a/v2/nvim/lua/johnmutuma/plugins/lsp/mason.lua b/v2/nvim/lua/johnmutuma/plugins/lsp/mason.lua index feff578..4d310f7 100644 --- a/v2/nvim/lua/johnmutuma/plugins/lsp/mason.lua +++ b/v2/nvim/lua/johnmutuma/plugins/lsp/mason.lua @@ -1,44 +1,38 @@ local mason_ok, mason = pcall(require, "mason") local mason_lspconfig_ok, mason_lspconfig = pcall(require, "mason-lspconfig") +local lspconfig_ok, lspconfig = pcall(require, "lspconfig") + local mason_null_ls_ok, mason_null_ls = pcall(require, "mason-null-ls") +local cmp_nvim_lsp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +local typescript_ok, typescript = pcall(require, "typescript") --- Configure LSP bucket -local set_up_lsp = function() - mason_lspconfig.setup({ - ensure_installed = { - "ts_ls", - "html", - "cssls", - -- "jsonls", -- preferring coc-json for workspace features - "lua_ls", - "eslint", - "gopls", - }, - }) -end +local keymap = vim.keymap +local capabilities = cmp_nvim_lsp.default_capabilities() --- Configure Linters(Code Actions, Diagnostics) & Formatters bucket -local set_up_linters_and_formatters = function() - mason_null_ls.setup({ - ensure_installed = { - "prettier", - "stylua", - "eslint", - "cspell", - "gofumpt", - }, - }) -end +-- Configure Language servers LSP +local ensure_installed_lsp = { + "ts_ls", + "html", + "cssls", + "lua_ls", + "eslint", + "gopls", + -- "jsonls", -- preferring coc-json for workspace features +} --- Configure DAP bucket -local set_up_debuggers = function() end --- +-- Configure Linters(Code Actions, Diagnostics) & Formatters bucket +local ensure_installed_null_ls = { + "prettier", + "stylua", + "eslint", + "cspell", + "gofumpt", +} -local main = function() - mason.setup() - set_up_lsp() - set_up_linters_and_formatters() - set_up_debuggers() +-- Sanity checks +if not cmp_nvim_lsp_ok then + print("cmp_nvim_lsp could not be loaded") + return end if not mason_ok then @@ -51,9 +45,155 @@ if not mason_lspconfig_ok then return end +if not lspconfig_ok then + print("lspconfig could not be loaded") + return +end + if not mason_null_ls_ok then print("mason_null_ls_ok could not be loaded") return end -main() +if not typescript_ok then + print("jose-elias-alvarez/typescript could not be loaded") + return +end + +-- Set up Mason +mason.setup() + +local set_up_lsp = function(on_attach) + mason_lspconfig.setup({ + ensure_installed = ensure_installed_lsp, + handlers = { + -- The first entry (without a key) will be the default handler + -- and will be called for each installed server that doesn't have + -- a dedicated handler. + function(server_name) -- default handler (optional) + lspconfig[server_name].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + end, + + ["lua_ls"] = function() + lspconfig["lua_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + + on_init = function(client) + if client.workspace_folders then + local path = client.workspace_folders[1].name + if vim.uv.fs_stat(path .. "/.luarc.json") or vim.uv.fs_stat(path .. "/.luarc.jsonc") then + return + end + end + + client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + -- Make the server aware of Neovim runtime files + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME, + -- Depending on the usage, you might want to add additional paths here. + -- "${3rd}/luv/library" + -- "${3rd}/busted/library", + }, + -- or pull in all of 'runtimepath'. NOTE: this is a lot slower and will cause issues when working on your own configuration (see https://github.com/neovim/nvim-lspconfig/issues/3189) + -- library = vim.api.nvim_get_runtime_file("", true) + }, + }) + end, + settings = { + Lua = {}, + }, + }) + end, + + ["gopls"] = function() + lspconfig["gopls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = true, + gofumpt = true, + }, + }, + }) + end, + + ["typescript"] = function() + typescript.setup({ + server = { + capabilities = capabilities, + on_attach = on_attach, + }, + }) + end, + }, + }) + -- typescript.setup({ + -- server = { + -- capabilities = capabilities, + -- on_attach = on_attach, + -- }, + -- }) +end + +local set_up_linters_and_formatters = function(on_attach) + mason_null_ls.setup({ + ensure_installed = ensure_installed_null_ls, + automaticinstallation = false, + handlers = {}, + }) +end + +-- Configure DAP bucket +local set_up_debuggers = function(on_attach) end +-- + +local on_attach = function(client, bufnr) + -- some language servers crash on semantic tokens when previewing files quickly e.g. Glance previews + -- disabling sematic tokens - hihglighting for now will be provided by nvim-treesitter + -- client.server_capabilities.semanticTokensProvider = nil + + local opts = { noremap = true, buffer = bufnr, silent = true } + -- LSP key bindings + keymap.set("n", "gR", "Glance references", opts) + -- keymap.set("n", "gR", "Lspsaga finder", opts) + -- keymap.set("n", "gd", "Lspsaga peek_definition", opts) + keymap.set("n", "gd", "Glance definitions", opts) + keymap.set("n", "gi", "Glance implementations") + keymap.set("n", "gT", "Glance type_definitions") + keymap.set("n", "g>", "Lspsaga outgoing_calls") + keymap.set("n", "g<", "Lspsaga incoming_calls") + keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + -- keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + -- keymap.set("n", "gr", vim.lsp.buf.references, opts) + keymap.set("n", "ca", "Lspsaga code_action", opts) + keymap.set("n", "rn", "Lspsaga rename", opts) + keymap.set("n", "]e", "Lspsaga diagnostic_jump_next", opts) + keymap.set("n", "[e", "Lspsaga diagnostic_jump_previous", opts) + keymap.set("n", "D", "Lspsaga show_buf_diagnostics", opts) + keymap.set("n", "d", "Lspsaga show_line_diagnostics", opts) + keymap.set("n", "wd", "Lspsaga show_workspace_diagnostics", opts) + keymap.set("n", "K", "Lspsaga hover_doc", opts) + + if client.name == "ts_ls" then + keymap.set("n", "rf", "TypescriptRenameFile", opts) + end +end + +set_up_lsp(on_attach) +set_up_linters_and_formatters(on_attach) +set_up_debuggers(on_attach) diff --git a/v2/nvim/lua/johnmutuma/plugins/lsp/null-ls.lua b/v2/nvim/lua/johnmutuma/plugins/lsp/null-ls.lua index 33f21f6..a5c1196 100644 --- a/v2/nvim/lua/johnmutuma/plugins/lsp/null-ls.lua +++ b/v2/nvim/lua/johnmutuma/plugins/lsp/null-ls.lua @@ -1,42 +1,13 @@ local null_ls_ok, null_ls = pcall(require, "null-ls") --- local eslint_ok, lspconfig = pcall(require, "lspconfig") --- if not eslint_ok then --- print("ESLint could not be loaded") --- return --- end - -local formatting = null_ls.builtins.formatting -local code_actions = null_ls.builtins.code_actions -local diagnostics = null_ls.builtins.diagnostics - --- local eslint = lspconfig["eslint"] --- eslint.setup({ --- capabilities = require("cmp_nvim_lsp").default_capabilities(), --- on_attach = function() --- return nil --- end, --- }) --- --- Configure linters, formatters, diagnostics, code actions -local set_up_linters_and_formatters = function(on_attach) - null_ls.setup({ - debug = false, - sources = { - -- code_actions.gitsigns, - formatting.stylua, - formatting.prettier, - formatting.gofumpt, - }, - on_attach = function(client, bufnr) - on_attach(client, bufnr) - end, - root_dir = function(_) - return nil - end, - }) +if not null_ls_ok then + print("null_ls could not be loaded") + return end +-- local code_actions = null_ls.builtins.code_actions +-- local diagnostics = null_ls.builtins.diagnostics + -- Format on save helper local augroup = vim.api.nvim_create_augroup("LspFormatting", { clear = true }) local configure_format_on_save = function(client, bufnr) @@ -52,15 +23,16 @@ local configure_format_on_save = function(client, bufnr) }) end end - --- Configure linting and formatting sources -local main = function() - set_up_linters_and_formatters(configure_format_on_save) -end - -if not null_ls_ok then - print("null_ls could not be loaded") - return -end - -main() +-- +-- Configure linters, formatters, diagnostics, code actions +null_ls.setup({ + debug = false, + -- sources = { + -- -- use this section to add sources unsupported by Mason yet + -- -- code_actions.gitsigns, + -- }, + on_attach = configure_format_on_save, + root_dir = function(_) + return nil + end, +}) diff --git a/v2/nvim/lua/johnmutuma/plugins/nvim-ide.lua b/v2/nvim/lua/johnmutuma/plugins/nvim-ide.lua index 84a7e99..aabf19d 100644 --- a/v2/nvim/lua/johnmutuma/plugins/nvim-ide.lua +++ b/v2/nvim/lua/johnmutuma/plugins/nvim-ide.lua @@ -84,3 +84,4 @@ icons.global_icon_set.set_icon("IndentGuide", "|") -- nvim-ide keymaps vim.keymap.set("n", "tr", ":Workspace RightPanelToggle", {}) +vim.keymap.set("n", "bf", ":Workspace BufferList Focus", {})