From 4e95af5b7af954a113193472fb7f733f167806a8 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 19:59:21 +0200 Subject: [PATCH 1/9] [dwm] fresh restart: update to 6.3 --- .local/src/dwm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.local/src/dwm b/.local/src/dwm index f8ad07e..82003c8 160000 --- a/.local/src/dwm +++ b/.local/src/dwm @@ -1 +1 @@ -Subproject commit f8ad07e02878adfbdab1241869630d608566c5c0 +Subproject commit 82003c8dad7b966ab65f339749fb4272eafb8f4b From 98b6a428a7d504d6961943a35e8338fe2ed0fe22 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 20:05:27 +0200 Subject: [PATCH 2/9] [nvim] feat: packer boostrapping on first install --- .config/nvim/lua/plugin/packer.lua | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua index 0af119b..91a1a3e 100644 --- a/.config/nvim/lua/plugin/packer.lua +++ b/.config/nvim/lua/plugin/packer.lua @@ -4,14 +4,19 @@ -- Description : neovim plugins file -local execute = vim.api.nvim_command -local fn = vim.fn - -local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim" - -if fn.empty(fn.glob(install_path)) > 0 then - fn.system({"git", "clone", "https://github.com/wbthomason/packer.nvim", install_path}) - execute "packadd packer.nvim" +local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" +if vim.fn.empty(vim.fn.glob(install_path)) > 0 then + print("Cloning packer...") + PACKER_BOOTSTRAP = vim.fn.system({ + "git", + "clone", + "--depth", + "1", + "https://github.com/wbthomason/packer.nvim", + install_path, + }) + vim.cmd([[packadd packer.nvim]]) + print("Done.") end return require("packer").startup(function() @@ -102,4 +107,10 @@ return require("packer").startup(function() "norcalli/nvim-colorizer.lua", cmd = "ColorizerToggle" } + + + -- automatically setup the config after cloning + if PACKER_BOOTSTRAP then + require("packer").sync() + end end) From 9c53518d21de4be8e723e6a1ade0278b8c018a47 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 20:06:03 +0200 Subject: [PATCH 3/9] [nvim] cleanup: remove unused Colorizer plugin --- .config/nvim/lua/plugin/packer.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua index 91a1a3e..1b78c1c 100644 --- a/.config/nvim/lua/plugin/packer.lua +++ b/.config/nvim/lua/plugin/packer.lua @@ -100,12 +100,6 @@ return require("packer").startup(function() use { "windwp/nvim-autopairs", config = function() require('nvim-autopairs').setup() end - } - - -- display colors directly in editor - use { - "norcalli/nvim-colorizer.lua", - cmd = "ColorizerToggle" } From b38d33a09bc223c42346265984c8e5d8583f5d54 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 20:06:24 +0200 Subject: [PATCH 4/9] [nvim] feat: local `use` variable for lsp --- .config/nvim/lua/plugin/packer.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua index 1b78c1c..a223b30 100644 --- a/.config/nvim/lua/plugin/packer.lua +++ b/.config/nvim/lua/plugin/packer.lua @@ -19,6 +19,8 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then print("Done.") end +local use = require("packer").use + return require("packer").startup(function() -- packer manages itself use "wbthomason/packer.nvim" From b2c50db8045a15ffb1a8b77b848a0480be7a987f Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 20:07:09 +0200 Subject: [PATCH 5/9] [nvim] feat: Telescope is default --- .config/nvim/lua/plugin/packer.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua index a223b30..501008c 100644 --- a/.config/nvim/lua/plugin/packer.lua +++ b/.config/nvim/lua/plugin/packer.lua @@ -41,18 +41,14 @@ return require("packer").startup(function() -- fuzzy finder use { "nvim-telescope/telescope.nvim", - opt = true, requires = { { "nvim-lua/plenary.nvim", - opt = true }, {'nvim-telescope/telescope-fzf-native.nvim', - opt = true, run = 'make' } }, - cmd = "Telescope" } -- LSP From 40839ad70b50a77ccf0555e0c4ce8eda48455490 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 20:12:47 +0200 Subject: [PATCH 6/9] [nvim] feat: configure LSPs through lsp-installer !!!BREAK: do not use lsp-config (used under the hood by nvim-lsp-installer) --- .config/nvim/lua/lsp/c.lua | 20 ---- .config/nvim/lua/lsp/init.lua | 5 +- .config/nvim/lua/lsp/lua.lua | 40 -------- .config/nvim/lua/lsp/python.lua | 8 -- .config/nvim/lua/lsp/tex.lua | 13 --- .config/nvim/lua/plugin/lsp_installer.lua | 106 +++++++++++++++++++--- .config/nvim/lua/plugin/packer.lua | 14 +-- 7 files changed, 97 insertions(+), 109 deletions(-) delete mode 100644 .config/nvim/lua/lsp/c.lua delete mode 100644 .config/nvim/lua/lsp/lua.lua delete mode 100644 .config/nvim/lua/lsp/python.lua delete mode 100644 .config/nvim/lua/lsp/tex.lua diff --git a/.config/nvim/lua/lsp/c.lua b/.config/nvim/lua/lsp/c.lua deleted file mode 100644 index 986eca3..0000000 --- a/.config/nvim/lua/lsp/c.lua +++ /dev/null @@ -1,20 +0,0 @@ --- Author : swytch --- Created : Tuesday May 18, 2021 12:08:51 CET --- License : GPLv3 --- Description : clangd config file for lsp - --- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers.. -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) - - -require("lspconfig").clangd.setup { - cmd = { "clangd", - "--background-index", - "--suggest-missing-includes", - "--clang-tidy", - "--header-insertion=iwyu" - }, - -- The following example advertise capabilities to `clangd`. - capabilities = capabilities, -} diff --git a/.config/nvim/lua/lsp/init.lua b/.config/nvim/lua/lsp/init.lua index 4fbc92a..1cbd609 100644 --- a/.config/nvim/lua/lsp/init.lua +++ b/.config/nvim/lua/lsp/init.lua @@ -66,15 +66,12 @@ M.icons = { Variable = "  ", } + function M.setup() local kinds = vim.lsp.protocol.CompletionItemKind for i, kind in ipairs(kinds) do kinds[i] = M.icons[kind] or kind end - - local ft = vim.bo.filetype - if ft == "cpp" then ft = "c" end - require("lsp." .. ft) -- ./.lua end return M diff --git a/.config/nvim/lua/lsp/lua.lua b/.config/nvim/lua/lsp/lua.lua deleted file mode 100644 index 76caeb6..0000000 --- a/.config/nvim/lua/lsp/lua.lua +++ /dev/null @@ -1,40 +0,0 @@ --- Author : swytch --- Created : Tuesday May 18, 2021 12:08:51 CET --- License : GPLv3 --- Description : sumneko (lua) config file for lsp - - --- set the path to the sumneko installation; if you previously installed via the now deprecated :LspInstall, use -local sumneko_root_path = vim.fn.stdpath("data") .. - "/lsp_servers/sumneko_lua/extension/server" -local sumneko_binary = sumneko_root_path .. "/bin/" .. "/lua-language-server" - -local runtime_path = vim.split(package.path, ';') -table.insert(runtime_path, "lua/?.lua") -table.insert(runtime_path, "lua/?/init.lua") - -require'lspconfig'.sumneko_lua.setup { - cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}; - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - -- Setup your lua path - path = runtime_path, - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = {"vim", "use", "globals", "utils"}, - }, - 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, - }, - }, - }, -} diff --git a/.config/nvim/lua/lsp/python.lua b/.config/nvim/lua/lsp/python.lua deleted file mode 100644 index 466a94a..0000000 --- a/.config/nvim/lua/lsp/python.lua +++ /dev/null @@ -1,8 +0,0 @@ --- Author : swytch --- Created : Tuesday May 18, 2021 15:03:43 CET --- License : GPLv3 --- Description : jedi (python) config file for lsp - -require("lspconfig").jedi_language_server.setup{ - cmd = { vim.fn.stdpath("data") .. "/lsp_servers/jedi_language_server/venv/bin/jedi-language-server" } -} diff --git a/.config/nvim/lua/lsp/tex.lua b/.config/nvim/lua/lsp/tex.lua deleted file mode 100644 index a715ed9..0000000 --- a/.config/nvim/lua/lsp/tex.lua +++ /dev/null @@ -1,13 +0,0 @@ --- Author : swytch --- Created : Saturday May 23, 2021 10:34:53 CET --- License : GPLv3 --- Description : LaTeX config file for lsp - -require("lspconfig").texlab.setup { - cmd = { vim.fn.stdpath("data") .. "/lsp_servers/latex/texlab" }, - settings = { - build = { - executable = "pdflatex" - } - } -} diff --git a/.config/nvim/lua/plugin/lsp_installer.lua b/.config/nvim/lua/plugin/lsp_installer.lua index 70e929f..d296e04 100644 --- a/.config/nvim/lua/plugin/lsp_installer.lua +++ b/.config/nvim/lua/plugin/lsp_installer.lua @@ -9,20 +9,18 @@ lsp_installer.settings { ui = { icons = { server_installed = "✓", - server_pending = "➜", - server_uninstalled = "✗" + server_pending = "o", + server_uninstalled = "x" } } } local servers = { - "bashls", - "jedi_language_server", - "texlab", + "clangd", "sumneko_lua", } -for _, name in pairs(servers) do +for _, name in ipairs(servers) do local ok, server = lsp_installer.get_server(name) -- Check that the server is supported in nvim-lsp-installer if ok then @@ -33,15 +31,95 @@ for _, name in pairs(servers) do end end +local lsp_root_path = vim.fn.stdpath("data") .. "/lsp_servers/" +local runtime_path = vim.split(package.path, ';') + + +local clangd_binary = lsp_root_path .. "clangd/clangd/bin/clangd" + +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") + +local enhance_server_opts = { + ["clangd"] = function(opts) + opts.settings = { + cmd = { clangd_binary, + "--background-index", + "--suggest-missing-includes", + "--clang-tidy", + "--header-insertion=iwyu" + }, + } + end, + ["sumneko_lua"] = function(opts) + opts.settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + "vim", + "globals", + "utils" + }, + }, + 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, +} + +local on_attach = function(_, bufnr) + local opts = { buffer = bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', + vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', + vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + vim.inspect(vim.lsp.buf.list_workspace_folders()) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'so', + require('telescope.builtin').lsp_document_symbols, opts) + vim.api.nvim_create_user_command("Format", vim.lsp.buf.formatting, {}) +end + +-- nvim-cmp supports additional completion capabilities +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) + lsp_installer.on_server_ready(function(server) - local opts = {} + -- Specify the default options which we'll use to setup all servers + local opts = { + on_attach = on_attach, + capabilities = capabilities, + } - -- (optional) Customize the options passed to the server - -- if server.name == "tsserver" then - -- opts.root_dir = function() ... end - -- end + if enhance_server_opts[server.name] then + -- Enhance the default opts with the server-specific ones + enhance_server_opts[server.name](opts) + end - -- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart) - server:setup(opts) - vim.cmd [[ do User LspAttachBuffers ]] + server:setup(opts) end) diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua index 501008c..970e546 100644 --- a/.config/nvim/lua/plugin/packer.lua +++ b/.config/nvim/lua/plugin/packer.lua @@ -54,17 +54,11 @@ return require("packer").startup(function() -- LSP use { "williamboman/nvim-lsp-installer", - cmd = { - "LspInstall", - "LspInstallInfo" + requires = { + "neovim/nvim-lspconfig", + config = function() require("lsp").setup() end }, - config = function() require("plugin.lsp_installer").setup() end - } - - use { - "neovim/nvim-lspconfig", - ft = { "c", "cpp", "lua", "python", "tex"}, - config = function() require("lsp").setup() end + config = function() require("plugin.lsp_installer") end } -- auto completion From 9ff24a555979fc14c52d9bc2c2bf211aafacae86 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 20:17:26 +0200 Subject: [PATCH 7/9] [nvim] cleanup: move lspconfig.lua to lua/plugin/ --- .config/nvim/lua/{lsp/init.lua => plugin/lsp_config.lua} | 0 .config/nvim/lua/plugin/packer.lua | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) rename .config/nvim/lua/{lsp/init.lua => plugin/lsp_config.lua} (100%) diff --git a/.config/nvim/lua/lsp/init.lua b/.config/nvim/lua/plugin/lsp_config.lua similarity index 100% rename from .config/nvim/lua/lsp/init.lua rename to .config/nvim/lua/plugin/lsp_config.lua diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua index 970e546..d866f94 100644 --- a/.config/nvim/lua/plugin/packer.lua +++ b/.config/nvim/lua/plugin/packer.lua @@ -56,7 +56,8 @@ return require("packer").startup(function() "williamboman/nvim-lsp-installer", requires = { "neovim/nvim-lspconfig", - config = function() require("lsp").setup() end + config = function() + require("plugin.lsp_config").setup() end }, config = function() require("plugin.lsp_installer") end } From bc67eb8ffe2ca8203bcb73a834231981aff300fe Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 21:30:56 +0200 Subject: [PATCH 8/9] [nvim] feat: update mapping API nvim 0.7 has a dedicated keymap.set function --- .config/nvim/lua/maps.lua | 40 +++++++++++------------ .config/nvim/lua/plugin/lsp_installer.lua | 32 +++++++++--------- .config/nvim/lua/utils.lua | 6 ---- 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/.config/nvim/lua/maps.lua b/.config/nvim/lua/maps.lua index 54c0c79..d4bc6d5 100644 --- a/.config/nvim/lua/maps.lua +++ b/.config/nvim/lua/maps.lua @@ -3,30 +3,30 @@ -- License : GPLv3 -- Description : neovim mappings file -utils.map("n", "", "") -utils.map("n", "y", "\"+y") -utils.map("n", "p", "\"+P") -utils.map("n", "", "w! | !compiler %") -utils.map("n", "u", "PackerSync") -utils.map("n", "c", "ColorizerToggle") +vim.keymap.set({ "n", "v" }, "", "", { silent = true }) +vim.g.mapleader = " " --- LSP -utils.map("n", "gd", "lua vim.lsp.buf.definition()") -utils.map("n", "gD", "lua vim.lsp.buf.declaration()") -utils.map("n", "gr", "lua vim.lsp.buf.references()") -utils.map("n", "gi", "lua vim.lsp.buf.implementation()") -utils.map("n", "ln", "lua vim.diagnostic.goto_next()") -utils.map("n", "lp", "lua vim.diagnostic.goto_prev()") -utils.map("n", "lf", "lua vim.lsp.buf.formatting()") +-- Dealing with word wrap +vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", + { expr = true, silent = true }) +vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", + { expr = true, silent = true }) + +vim.keymap.set("n", "y", "\"+y") +vim.keymap.set("n", "p", "\"+P") +vim.keymap.set("n", "", "w! | !compiler %") +vim.keymap.set("n", "u", function() require("packer").sync() end) -- telescope -utils.map("n", "ff", "Telescope find_files") -utils.map("n", "fb", "Telescope buffers") -utils.map("n", "fl", "Telescope live_grep") +vim.keymap.set("n", "ff", + function() require("telescope.builtin").find_files() end) +vim.keymap.set("n", "fb", + function() require("telescope.builtin").buffers() end) +vim.keymap.set("n", "fl", + function() require("telescope.builtin").live_grep() end) -- colorscheme -utils.map("n", "", "lua require(\"astronomy\").toggle_variant()") +vim.keymap.set("n", "", function() require("astronomy").toggle_variant() end) -- snippets -utils.map("i", "", "luasnip-next-choice", {}) -utils.map("s", "", "luasnip-next-choice", {}) +vim.keymap.set({ "i", "s" }, "", "luasnip-next-choice") diff --git a/.config/nvim/lua/plugin/lsp_installer.lua b/.config/nvim/lua/plugin/lsp_installer.lua index d296e04..45852c6 100644 --- a/.config/nvim/lua/plugin/lsp_installer.lua +++ b/.config/nvim/lua/plugin/lsp_installer.lua @@ -84,25 +84,27 @@ local enhance_server_opts = { local on_attach = function(_, bufnr) local opts = { buffer = bufnr } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) - vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) - vim.keymap.set('n', 'wa', + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + vim.keymap.set("n", "ln", vim.diagnostic.goto_next, opts) + vim.keymap.set("n", "lp", vim.diagnostic.goto_prev, opts) + vim.keymap.set("n", "lf", vim.lsp.buf.formatting, opts) + vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts) - vim.keymap.set('n', 'wr', + vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) - vim.keymap.set('n', 'wl', function() + vim.keymap.set("n", "wl", function() vim.inspect(vim.lsp.buf.list_workspace_folders()) end, opts) - vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) - vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, opts) - vim.keymap.set('n', 'so', - require('telescope.builtin').lsp_document_symbols, opts) - vim.api.nvim_create_user_command("Format", vim.lsp.buf.formatting, {}) + vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) + vim.keymap.set("n", "so", + require("telescope.builtin").lsp_document_symbols, opts) end -- nvim-cmp supports additional completion capabilities diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua index 34eb80e..9ea50dc 100644 --- a/.config/nvim/lua/utils.lua +++ b/.config/nvim/lua/utils.lua @@ -22,12 +22,6 @@ function M.add_rtp(path) rtp = rtp .. "," .. path end --- map a key with optional options -function M.map(mode, keys, action, options) - options = options or {} - vim.api.nvim_set_keymap(mode, keys, action, options) -end - -- see if a file exists function M.file_exists(file) local f = io.open(file, "rb") From d9e7f76a5fb7e8c860bca0d16e5fc7c335b2f9b0 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Wed, 27 Apr 2022 21:58:12 +0200 Subject: [PATCH 9/9] [nvim] format: tabstop=8 -> 4 for lua files --- .config/nvim/after/ftplugin/c.lua | 30 +- .config/nvim/after/ftplugin/lua.lua | 3 +- .config/nvim/after/ftplugin/tex.lua | 185 +++++++------ .config/nvim/lua/colorscheme.lua | 2 +- .config/nvim/lua/globals.lua | 12 +- .config/nvim/lua/maps.lua | 13 +- .config/nvim/lua/plugin/cmp.lua | 132 ++++----- .config/nvim/lua/plugin/lsp_config.lua | 106 ++++---- .config/nvim/lua/plugin/lsp_installer.lua | 144 +++++----- .config/nvim/lua/plugin/packer.lua | 161 +++++------ .config/nvim/lua/plugin/treesitter.lua | 16 +- .config/nvim/lua/settings.lua | 62 ++--- .config/nvim/lua/statusline.lua | 318 +++++++++++----------- 13 files changed, 593 insertions(+), 591 deletions(-) diff --git a/.config/nvim/after/ftplugin/c.lua b/.config/nvim/after/ftplugin/c.lua index ad16ca6..e75fba3 100644 --- a/.config/nvim/after/ftplugin/c.lua +++ b/.config/nvim/after/ftplugin/c.lua @@ -4,10 +4,10 @@ -- Description : c settings file -local opt = vim.opt -local g = vim.g +local opt = vim.opt +local g = vim.g -opt.formatoptions = "trq1jp" +opt.formatoptions = "trq1jp" -- Snippets local ls = require("luasnip") @@ -21,14 +21,14 @@ local f = ls.function_node local copy = utils.copy ls.snippets = { - c = { - s("main", { - t({ "int main(int argc, char* argv[])" }), - t({ "", "{", "\t" }), - i(0), - t({ "", "\treturn 0;"}), - t({ "", "}"}), - }), + c = { + s("main", { + t({ "int main(int argc, char* argv[])" }), + t({ "", "{", "\t" }), + i(0), + t({ "", "\treturn 0;"}), + t({ "", "}"}), + }), s("fn", { -- Simple static text. t("//Parameters: "), @@ -43,9 +43,9 @@ ls.snippets = { i(2, "int foo"), -- Linebreak t({ ")", "{", "\t" }), - i(0), - t({ "", "\treturn 0;"}), - t({ "", "}"}), - }), + i(0), + t({ "", "\treturn 0;"}), + t({ "", "}"}), + }), }, } diff --git a/.config/nvim/after/ftplugin/lua.lua b/.config/nvim/after/ftplugin/lua.lua index 698ac52..ff3633d 100644 --- a/.config/nvim/after/ftplugin/lua.lua +++ b/.config/nvim/after/ftplugin/lua.lua @@ -6,4 +6,5 @@ local opt = vim.opt local g = vim.g -opt.formatoptions = "trq1jp" +opt.formatoptions = "trq1jp" +opt.tabstop = 4 diff --git a/.config/nvim/after/ftplugin/tex.lua b/.config/nvim/after/ftplugin/tex.lua index 01a07c2..71c702f 100644 --- a/.config/nvim/after/ftplugin/tex.lua +++ b/.config/nvim/after/ftplugin/tex.lua @@ -4,11 +4,10 @@ -- Description : tex filetype config -local opt = vim.opt -local g = vim.g +local opt = vim.opt -opt.formatoptions = "trq1jp" -opt.tabstop = 4 +opt.formatoptions = "trq1jp" +opt.tabstop = 4 -- Caps utils.map("i", "AA", "À") @@ -23,15 +22,15 @@ utils.map("i", ":", "\\,:") local ls = require("luasnip") -- some shorthands... -local s = ls.snippet -local sn = ls.snippet_node -local t = ls.text_node -local i = ls.insert_node -local f = ls.function_node -local c = ls.choice_node -local d = ls.dynamic_node +local s = ls.snippet +local sn = ls.snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node -local copy = utils.copy +local copy = utils.copy -- 'recursive' dynamic snippet. Expands to some text followed by itself. local function rec_ls() @@ -46,85 +45,85 @@ local function rec_ls() end ls.snippets = { - tex = { - -- rec_ls is self-referencing. That makes this snippet 'infinite' eg. have as many - -- \item as necessary by utilizing a choiceNode. - s("ls", { - t({ "\\begin{itemize}", "\t\\item " }), - i(1), - t({ "" }), - d(2, rec_ls, {}), - t({ "", "\\end{itemize}", "" }), - }), - s("lsl", { - t({ "\\begin{itemize}[label=" }), - i(1), - t( { "]", "\t\\item " }), - i(2), - t({ "" }), - d(3, rec_ls, {}), - t({ "", "\\end{itemize}", "" }), - }), - s("frm", { - t({ "\\begin{" }), - i(1), - t({ "}[" }), - i(2), - t({ "]{" }), - f(copy, 1), - t({ ":" }), - i(3, "foo"), - t({ "}", "\t" }), - i(0), - t({ "", "\\end{" }), - f(copy, 1), - t({ "}", "" }), - }), - s("env", { - t({ "\\begin{" }), - i(1, "foo"), - t({ "}", "\t" }), - i(2), - t({ "", "\\end{" }), - f(copy,1), - t({ "}"}), - }), - s("tikz", { - t({ "\\begin{center}" }), - t({ "", "\t\\begin{tikzpicture}[main/.style = {draw,circle}]", "\t\t" }), - i(1), - t({ "", "\t\\end{tikzpicture}", "\\end{center}" }), - }), - s("ra", { t( "\\rightarrow" )}), - s("Ra", { t("\\Rightarrow" )}), - s("la", { t("\\leftarrow" )}), - s("La", { t("\\Leftarrow" )}), - s("lra", { t("\\leftrightarrow" )}), - s("Lra", { t("\\Leftrightarrow" )}), - s("bb", { - t({ "\\textbf{" }), - i(1), - t({ "}"}), - }), - s("tt", { - t({ "\\texttt{" }), - i(1), - t({ "}"}), - }), - s("ii", { - t({ "\\textit{" }), - i(1), - t({ "}"}), - }), - s("uu", { - t({ "\\underline{" }), - i(1), - t({ "}"}), - }), - s("fsc", { - t({ "\\textsc{" }), - i(1), - t({ "}"}), - }), - }, + tex = { + -- rec_ls is self-referencing. That makes this snippet 'infinite' eg. have as many + -- \item as necessary by utilizing a choiceNode. + s("ls", { + t({ "\\begin{itemize}", "\t\\item " }), + i(1), + t({ "" }), + d(2, rec_ls, {}), + t({ "", "\\end{itemize}", "" }), + }), + s("lsl", { + t({ "\\begin{itemize}[label=" }), + i(1), + t( { "]", "\t\\item " }), + i(2), + t({ "" }), + d(3, rec_ls, {}), + t({ "", "\\end{itemize}", "" }), + }), + s("frm", { + t({ "\\begin{" }), + i(1), + t({ "}[" }), + i(2), + t({ "]{" }), + f(copy, 1), + t({ ":" }), + i(3, "foo"), + t({ "}", "\t" }), + i(0), + t({ "", "\\end{" }), + f(copy, 1), + t({ "}", "" }), + }), + s("env", { + t({ "\\begin{" }), + i(1, "foo"), + t({ "}", "\t" }), + i(2), + t({ "", "\\end{" }), + f(copy,1), + t({ "}"}), + }), + s("tikz", { + t({ "\\begin{center}" }), + t({ "", "\t\\begin{tikzpicture}[main/.style = {draw,circle}]", "\t\t" }), + i(1), + t({ "", "\t\\end{tikzpicture}", "\\end{center}" }), + }), + s("ra", { t( "\\rightarrow" )}), + s("Ra", { t("\\Rightarrow" )}), + s("la", { t("\\leftarrow" )}), + s("La", { t("\\Leftarrow" )}), + s("lra", { t("\\leftrightarrow" )}), + s("Lra", { t("\\Leftrightarrow" )}), + s("bb", { + t({ "\\textbf{" }), + i(1), + t({ "}"}), + }), + s("tt", { + t({ "\\texttt{" }), + i(1), + t({ "}"}), + }), + s("ii", { + t({ "\\textit{" }), + i(1), + t({ "}"}), + }), + s("uu", { + t({ "\\underline{" }), + i(1), + t({ "}"}), + }), + s("fsc", { + t({ "\\textsc{" }), + i(1), + t({ "}"}), + }), + }, } diff --git a/.config/nvim/lua/colorscheme.lua b/.config/nvim/lua/colorscheme.lua index 83dfddd..bebdd40 100644 --- a/.config/nvim/lua/colorscheme.lua +++ b/.config/nvim/lua/colorscheme.lua @@ -9,5 +9,5 @@ local file = os.getenv("XDG_STATE_HOME") .. "/nvim_colorscheme" local colorscheme = utils.lines_from(file)[0] require("astronomy").setup { - variant = colorscheme, + variant = colorscheme, } diff --git a/.config/nvim/lua/globals.lua b/.config/nvim/lua/globals.lua index 8a77ef8..c19c6c3 100644 --- a/.config/nvim/lua/globals.lua +++ b/.config/nvim/lua/globals.lua @@ -6,13 +6,11 @@ local M = {} -- The module to export M = { - lsp_path = vim.fn.stdpath("data").. "/lsp", - - -- misc - sign_error = "", - sign_warning = "", - sign_hint = "", - sign_info = "", + -- misc + sign_error = "", + sign_warning = "", + sign_hint = "", + sign_info = "", } -- Make it accessible everywhere diff --git a/.config/nvim/lua/maps.lua b/.config/nvim/lua/maps.lua index d4bc6d5..5ee5ec4 100644 --- a/.config/nvim/lua/maps.lua +++ b/.config/nvim/lua/maps.lua @@ -8,9 +8,9 @@ vim.g.mapleader = " " -- Dealing with word wrap vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", - { expr = true, silent = true }) + { expr = true, silent = true }) vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", - { expr = true, silent = true }) + { expr = true, silent = true }) vim.keymap.set("n", "y", "\"+y") vim.keymap.set("n", "p", "\"+P") @@ -19,14 +19,15 @@ vim.keymap.set("n", "u", function() require("packer").sync() end) -- telescope vim.keymap.set("n", "ff", - function() require("telescope.builtin").find_files() end) + function() require("telescope.builtin").find_files() end) vim.keymap.set("n", "fb", - function() require("telescope.builtin").buffers() end) + function() require("telescope.builtin").buffers() end) vim.keymap.set("n", "fl", - function() require("telescope.builtin").live_grep() end) + function() require("telescope.builtin").live_grep() end) -- colorscheme -vim.keymap.set("n", "", function() require("astronomy").toggle_variant() end) +vim.keymap.set("n", "", + function() require("astronomy").toggle_variant() end) -- snippets vim.keymap.set({ "i", "s" }, "", "luasnip-next-choice") diff --git a/.config/nvim/lua/plugin/cmp.lua b/.config/nvim/lua/plugin/cmp.lua index 863282b..5727339 100644 --- a/.config/nvim/lua/plugin/cmp.lua +++ b/.config/nvim/lua/plugin/cmp.lua @@ -8,76 +8,76 @@ local luasnip = require("luasnip") local cmp_autopairs = require('nvim-autopairs.completion.cmp') local check_backspace = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and - vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]: - sub(col, col):match('%s') == nil + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and + vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]: + sub(col, col):match('%s') == nil end -- If you want insert `(` after select function or method item cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) cmp.setup { - completion = { - autocomplete = false - }, - sources = { - { name = "path" }, - { name = "luasnip" }, - { name = "nvim_lsp" }, - { name = "buffer" }, - { name = "nvim_lua" }, - { name = "calc" }, - { name = "spell" }, - { name = "treesitter" }, - }, - formatting = { - format = function(entry, vim_item) - vim_item.menu = ({ - nvim_lsp = "[lsp]", - nvim_lua = "[nvim]", - luasnip = "[snip]", - path = "[path]", - buffer = "[buff]", - calc = "[calc]", - spell = "[spel]", - treesitter = "[tree]", - })[entry.source.name] - return vim_item - end, - }, - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = { - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif check_backspace() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - } + completion = { + autocomplete = false + }, + sources = { + { name = "path" }, + { name = "luasnip" }, + { name = "nvim_lsp" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "calc" }, + { name = "spell" }, + { name = "treesitter" }, + }, + formatting = { + format = function(entry, vim_item) + vim_item.menu = ({ + nvim_lsp = "[lsp]", + nvim_lua = "[nvim]", + luasnip = "[snip]", + path = "[path]", + buffer = "[buff]", + calc = "[calc]", + spell = "[spel]", + treesitter = "[tree]", + })[entry.source.name] + return vim_item + end, + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + } } diff --git a/.config/nvim/lua/plugin/lsp_config.lua b/.config/nvim/lua/plugin/lsp_config.lua index 1cbd609..fb00539 100644 --- a/.config/nvim/lua/plugin/lsp_config.lua +++ b/.config/nvim/lua/plugin/lsp_config.lua @@ -6,72 +6,72 @@ local M = {} vim.fn.sign_define( - "DiagnosticSignError", - { - texthl = "DiagnosticVirtualTextError", - text = globals.sign_error, - numhl = "DiagnosticSignError" - } + "DiagnosticSignError", + { + texthl = "DiagnosticVirtualTextError", + text = globals.sign_error, + numhl = "DiagnosticSignError" + } ) vim.fn.sign_define( - "DiagnosticSignWarn", - { - texthl = "DiagnosticVirtualTextWarn", - text = globals.sign_warning, - numhl = "DiagnosticSignWarn" - } + "DiagnosticSignWarn", + { + texthl = "DiagnosticVirtualTextWarn", + text = globals.sign_warning, + numhl = "DiagnosticSignWarn" + } ) vim.fn.sign_define( - "DiagnosticSignHint", - { - texthl = "DiagnosticVirtualTextHint", - text = globals.sign_hint, - numhl = "DiagnosticSignHint" - } + "DiagnosticSignHint", + { + texthl = "DiagnosticVirtualTextHint", + text = globals.sign_hint, + numhl = "DiagnosticSignHint" + } ) vim.fn.sign_define( - "DiagnosticSignInfo", - { - texthl = "DiagnosticVirtualTextInfo", - text = globals.sign_info, - numhl = "DiagnosticSignInfo" - } + "DiagnosticSignInfo", + { + texthl = "DiagnosticVirtualTextInfo", + text = globals.sign_info, + numhl = "DiagnosticSignInfo" + } ) M.icons = { - Class = "  ", - Color = "  ", - Constant = " µ ", - Constructor = "  ", - Enum = "  ", - EnumMember = "  ", - Event = "  ", - Field = "  ", - File = "  ", - Folder = "  ", - Function = "  ", - Keyword = "  ", - Interface = "  ", - Method = "  ", - Module = "  ", - Operator = "  ", - Property = "  ", - Reference = "  ", - Snippet = "  ", - Struct = "  ", - Text = "  ", - TypeParameter = "  ", - Unit = "  ", - Value = "  ", - Variable = "  ", + Class = "  ", + Color = "  ", + Constant = " µ ", + Constructor = "  ", + Enum = "  ", + EnumMember = "  ", + Event = "  ", + Field = "  ", + File = "  ", + Folder = "  ", + Function = "  ", + Keyword = "  ", + Interface = "  ", + Method = "  ", + Module = "  ", + Operator = "  ", + Property = "  ", + Reference = "  ", + Snippet = "  ", + Struct = "  ", + Text = "  ", + TypeParameter = "  ", + Unit = "  ", + Value = "  ", + Variable = "  ", } function M.setup() - local kinds = vim.lsp.protocol.CompletionItemKind - for i, kind in ipairs(kinds) do - kinds[i] = M.icons[kind] or kind - end + local kinds = vim.lsp.protocol.CompletionItemKind + for i, kind in ipairs(kinds) do + kinds[i] = M.icons[kind] or kind + end end return M diff --git a/.config/nvim/lua/plugin/lsp_installer.lua b/.config/nvim/lua/plugin/lsp_installer.lua index 45852c6..ab3b51c 100644 --- a/.config/nvim/lua/plugin/lsp_installer.lua +++ b/.config/nvim/lua/plugin/lsp_installer.lua @@ -41,70 +41,72 @@ table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") local enhance_server_opts = { - ["clangd"] = function(opts) - opts.settings = { - cmd = { clangd_binary, - "--background-index", - "--suggest-missing-includes", - "--clang-tidy", - "--header-insertion=iwyu" - }, - } - end, - ["sumneko_lua"] = function(opts) - opts.settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - -- Setup your lua path - path = runtime_path, - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { - "vim", - "globals", - "utils" - }, - }, - 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, + ["clangd"] = function(opts) + opts.settings = { + cmd = { clangd_binary, + "--background-index", + "--suggest-missing-includes", + "--clang-tidy", + "--header-insertion=iwyu" + }, + } + end, + ["sumneko_lua"] = function(opts) + opts.settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're + -- using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + "vim", + "globals", + "utils" + }, + }, + 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, } local on_attach = function(_, bufnr) - local opts = { buffer = bufnr } - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) - vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) - vim.keymap.set("n", "ln", vim.diagnostic.goto_next, opts) - vim.keymap.set("n", "lp", vim.diagnostic.goto_prev, opts) - vim.keymap.set("n", "lf", vim.lsp.buf.formatting, opts) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) - vim.keymap.set("n", "wa", - vim.lsp.buf.add_workspace_folder, opts) - vim.keymap.set("n", "wr", - vim.lsp.buf.remove_workspace_folder, opts) - vim.keymap.set("n", "wl", function() - vim.inspect(vim.lsp.buf.list_workspace_folders()) - end, opts) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) - vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) - vim.keymap.set("n", "so", - require("telescope.builtin").lsp_document_symbols, opts) + local opts = { buffer = bufnr } + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + vim.keymap.set("n", "ln", vim.diagnostic.goto_next, opts) + vim.keymap.set("n", "lp", vim.diagnostic.goto_prev, opts) + vim.keymap.set("n", "lf", vim.lsp.buf.formatting, opts) + vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "wa", + vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set("n", "wr", + vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set("n", "wl", function() + vim.inspect(vim.lsp.buf.list_workspace_folders()) + end, opts) + vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) + vim.keymap.set("n", "so", + require("telescope.builtin").lsp_document_symbols, opts) end -- nvim-cmp supports additional completion capabilities @@ -112,16 +114,16 @@ local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) lsp_installer.on_server_ready(function(server) - -- Specify the default options which we'll use to setup all servers - local opts = { - on_attach = on_attach, - capabilities = capabilities, - } + -- Specify the default options which we'll use to setup all servers + local opts = { + on_attach = on_attach, + capabilities = capabilities, + } - if enhance_server_opts[server.name] then - -- Enhance the default opts with the server-specific ones - enhance_server_opts[server.name](opts) - end + if enhance_server_opts[server.name] then + -- Enhance the default opts with the server-specific ones + enhance_server_opts[server.name](opts) + end - server:setup(opts) + server:setup(opts) end) diff --git a/.config/nvim/lua/plugin/packer.lua b/.config/nvim/lua/plugin/packer.lua index d866f94..dddeee8 100644 --- a/.config/nvim/lua/plugin/packer.lua +++ b/.config/nvim/lua/plugin/packer.lua @@ -6,98 +6,99 @@ local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - print("Cloning packer...") - PACKER_BOOTSTRAP = vim.fn.system({ - "git", - "clone", - "--depth", - "1", - "https://github.com/wbthomason/packer.nvim", - install_path, - }) - vim.cmd([[packadd packer.nvim]]) - print("Done.") + print("Cloning packer...") + PACKER_BOOTSTRAP = vim.fn.system({ + "git", + "clone", + "--depth", + "1", + "https://github.com/wbthomason/packer.nvim", + install_path, + }) + vim.cmd([[packadd packer.nvim]]) + print("Done.") end local use = require("packer").use return require("packer").startup(function() - -- packer manages itself - use "wbthomason/packer.nvim" + -- packer manages itself + use "wbthomason/packer.nvim" - -- colorscheme - use { - "~/.local/src/astronomy.nvim", - config = function() require("colorscheme") end - } + -- colorscheme + use { + "~/.local/src/astronomy.nvim", + config = function() require("colorscheme") end + } - -- tree-sitter - use { - "nvim-treesitter/nvim-treesitter", - run = ":TSUpdate", - config = function() require("plugin.treesitter") end - } + -- tree-sitter + use { + "nvim-treesitter/nvim-treesitter", + run = ":TSUpdate", + config = function() require("plugin.treesitter") end + } - -- fuzzy finder - use { - "nvim-telescope/telescope.nvim", - requires = { - { - "nvim-lua/plenary.nvim", - }, - {'nvim-telescope/telescope-fzf-native.nvim', - run = 'make' - } - }, - } + -- fuzzy finder + use { + "nvim-telescope/telescope.nvim", + requires = { + { + "nvim-lua/plenary.nvim", + }, + { + "nvim-telescope/telescope-fzf-native.nvim", + run = "make" + } + }, + } - -- LSP - use { - "williamboman/nvim-lsp-installer", - requires = { - "neovim/nvim-lspconfig", - config = function() - require("plugin.lsp_config").setup() end - }, - config = function() require("plugin.lsp_installer") end - } + -- LSP + use { + "williamboman/nvim-lsp-installer", + requires = { + "neovim/nvim-lspconfig", + config = function() + require("plugin.lsp_config").setup() end + }, + config = function() require("plugin.lsp_installer") end + } - -- auto completion - use { - "hrsh7th/nvim-cmp", - requires = { - { - "L3MON4D3/LuaSnip", - config = function() - require("plugin.luasnip") end - }, - "saadparwaiz1/cmp_luasnip", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-nvim-lua", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-calc", - "ray-x/cmp-treesitter", - "f3fora/cmp-spell", - }, - config = function() require("plugin.cmp") end - } + -- auto completion + use { + "hrsh7th/nvim-cmp", + requires = { + { + "L3MON4D3/LuaSnip", + config = function() + require("plugin.luasnip") end + }, + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-calc", + "ray-x/cmp-treesitter", + "f3fora/cmp-spell", + }, + config = function() require("plugin.cmp") end + } - -- commenting, simplified - use { - "numToStr/Comment.nvim", - config = function() require("plugin.comment") end - } + -- commenting, simplified + use { + "numToStr/Comment.nvim", + config = function() require("plugin.comment") end + } - -- autopairs - use { - "windwp/nvim-autopairs", - config = function() require('nvim-autopairs').setup() end - } + -- autopairs + use { + "windwp/nvim-autopairs", + config = function() require("nvim-autopairs").setup() end + } - -- automatically setup the config after cloning - if PACKER_BOOTSTRAP then - require("packer").sync() - end + -- automatically setup the config after cloning + if PACKER_BOOTSTRAP then + require("packer").sync() + end end) diff --git a/.config/nvim/lua/plugin/treesitter.lua b/.config/nvim/lua/plugin/treesitter.lua index e294959..0f70eb9 100644 --- a/.config/nvim/lua/plugin/treesitter.lua +++ b/.config/nvim/lua/plugin/treesitter.lua @@ -4,12 +4,12 @@ -- Description : treesitter config file require("nvim-treesitter.configs").setup { - ensure_installed = { "c", "lua", "python", "bash" }, - ignore_install = { "javascript" }, - highlight = { - enable = true, - }, - indent = { - enable = true, - }, + ensure_installed = { "c", "lua", "python", "bash" }, + ignore_install = { "javascript" }, + highlight = { + enable = true, + }, + indent = { + enable = true, + }, } diff --git a/.config/nvim/lua/settings.lua b/.config/nvim/lua/settings.lua index 08d21e9..b7fd6c1 100644 --- a/.config/nvim/lua/settings.lua +++ b/.config/nvim/lua/settings.lua @@ -7,7 +7,7 @@ local opt = vim.opt local g = vim.g -- general -opt.wildignore = { +opt.wildignore = { ".git", "*.o", "*.class", "*.jpg", "*.jpeg", "*.png", @@ -18,41 +18,41 @@ opt.wildmode = { "longest", "full" } opt.wildoptions = "pum" -- editor -opt.lazyredraw = true -opt.splitright = true -opt.splitbelow = true -opt.scrolloff = 4 -opt.termguicolors = true -opt.background = "dark" -opt.cursorline = true -opt.shortmess = opt.shortmess:append { c = true } -opt.number = true -opt.relativenumber = true -opt.signcolumn = "yes" -opt.listchars = { - tab = "<->", - nbsp = "␣", - trail = "·", - extends = ">", - precedes = "<", +opt.lazyredraw = true +opt.splitright = true +opt.splitbelow = true +opt.scrolloff = 4 +opt.termguicolors = true +opt.background = "dark" +opt.cursorline = true +opt.shortmess = opt.shortmess:append { c = true } +opt.number = true +opt.relativenumber = true +opt.signcolumn = "yes" +opt.listchars = { + tab = "<->", + nbsp = "␣", + trail = "·", + extends = ">", + precedes = "<", } -opt.showmatch = true -opt.ignorecase = true -opt.smartcase = true -opt.inccommand = "split" -opt.completeopt = { "menuone", "noselect" } +opt.showmatch = true +opt.ignorecase = true +opt.smartcase = true +opt.inccommand = "split" +opt.completeopt = { "menuone", "noselect" } -- statusline -opt.laststatus = 2 -opt.showmode = false +opt.laststatus = 2 +opt.showmode = false -- text, tabs, indents -opt.textwidth = 79 -opt.shiftwidth = 8 -opt.softtabstop = -1 -opt.expandtab = true -opt.shiftwidth = 0 -opt.backspace = { "indent", "eol", "start" } +opt.textwidth = 79 +opt.shiftwidth = 8 +opt.softtabstop = -1 +opt.expandtab = true +opt.shiftwidth = 0 +opt.backspace = { "indent", "eol", "start" } -- augroups utils.create_augroup({ diff --git a/.config/nvim/lua/statusline.lua b/.config/nvim/lua/statusline.lua index 65e2f4d..88d438a 100644 --- a/.config/nvim/lua/statusline.lua +++ b/.config/nvim/lua/statusline.lua @@ -6,204 +6,204 @@ local function gen_section(hl_string, items) - local out = "" - for _, item in pairs(items) do - if item ~= "" then - out = out .. " " .. item - end - end - if out ~="" then - return hl_string .. out .. " " - else - return out + local out = "" + for _, item in pairs(items) do + if item ~= "" then + out = out .. " " .. item end + end + if out ~="" then + return hl_string .. out .. " " + else + return out + end end -- sensible names for vim modes local function get_mode(m) - local mode_group = { - ["n"] = "Normal", - ["no"] = "O-Pending", - ["nov"] = "O-Pending", - ["noV"] = "O-Pending", - ["no"] = "O-Pending", - ["niI"] = "Normal", - ["niR"] = "Normal", - ["niV"] = "Normal", - ["v"] = "Visual", - ["V"] = "V-Line", - [""] = "V-Block", - ["s"] = "Select", - ["S"] = "S-Line", - [""] = "S-Block", - ["i"] = "Insert", - ["ic"] = "Insert", - ["ix"] = "Insert", - ["R"] = "Replace", - ["Rc"] = "Replace", - ["Rv"] = "V-Replace", - ["Rx"] = "Replace", - ["c"] = "Command", - ["cv"] = "Ex", - ["ce"] = "Ex", - ["r"] = "Prompt", - ["rm"] = "Prompt", - ["r?"] = "Prompt", - ["!"] = "Shell", - ["t"] = "Terminal", - } - return mode_group[m] or "None" + local mode_group = { + ["n"] = "Normal", + ["no"] = "O-Pending", + ["nov"] = "O-Pending", + ["noV"] = "O-Pending", + ["no"] = "O-Pending", + ["niI"] = "Normal", + ["niR"] = "Normal", + ["niV"] = "Normal", + ["v"] = "Visual", + ["V"] = "V-Line", + [""] = "V-Block", + ["s"] = "Select", + ["S"] = "S-Line", + [""] = "S-Block", + ["i"] = "Insert", + ["ic"] = "Insert", + ["ix"] = "Insert", + ["R"] = "Replace", + ["Rc"] = "Replace", + ["Rv"] = "V-Replace", + ["Rx"] = "Replace", + ["c"] = "Command", + ["cv"] = "Ex", + ["ce"] = "Ex", + ["r"] = "Prompt", + ["rm"] = "Prompt", + ["r?"] = "Prompt", + ["!"] = "Shell", + ["t"] = "Terminal", + } + return mode_group[m] or "None" end local function get_mode_display_name(m) - local mode = { - ["Normal"] = "[ NRM ]", - ["O-Pending"] = "[ OTR ]", - ["Visual"] = "[ VSL ]", - ["V-Line"] = "[ V·L ]", - ["V-Block"] = "[ V·B ]", - ["Select"] = "[ SEL ]", - ["S-Line"] = "[ S·L ]", - ["S-Block"] = "[ S·B ]", - ["Insert"] = "[ INS ]", - ["Replace"] = "[ RPL ]", - ["Command"] = "[ CMD ]", - ["Prompt"] = "[ PMT ]", - ["Shell"] = "[ SHL ]", - ["Terminal"] = "[ TRM ]", - ["None"] = "[ --- ]" - } - return mode[m] + local mode = { + ["Normal"] = "[ NRM ]", + ["O-Pending"] = "[ OTR ]", + ["Visual"] = "[ VSL ]", + ["V-Line"] = "[ V·L ]", + ["V-Block"] = "[ V·B ]", + ["Select"] = "[ SEL ]", + ["S-Line"] = "[ S·L ]", + ["S-Block"] = "[ S·B ]", + ["Insert"] = "[ INS ]", + ["Replace"] = "[ RPL ]", + ["Command"] = "[ CMD ]", + ["Prompt"] = "[ PMT ]", + ["Shell"] = "[ SHL ]", + ["Terminal"] = "[ TRM ]", + ["None"] = "[ --- ]" + } + return mode[m] end -- get the highlight group for a mode group local function get_mode_color(m) - local color = { - ["Normal"] = "%#NormalMode#", - ["O-Pending"] = "%#NormalMode#", - ["Visual"] = "%#VisualMode#", - ["V-Line"] = "%#VisualMode#", - ["V-Block"] = "%#VisualMode#", - ["Select"] = "%#NormalMode#", - ["S-Line"] = "%#NormalMode#", - ["S-Block"] = "%#NormalMode#", - ["Insert"] = "%#InsertMode#", - ["Replace"] = "%#ReplaceMode#", - ["Command"] = "%#CommandMode#", - ["Prompt"] = "%#NormalMode#", - ["Shell"] = "%#NormalMode#", - ["Terminal"] = "%#NormalMode#", - ["None"] = "%#NormalMode#" - } - return color[m] + local color = { + ["Normal"] = "%#NormalMode#", + ["O-Pending"] = "%#NormalMode#", + ["Visual"] = "%#VisualMode#", + ["V-Line"] = "%#VisualMode#", + ["V-Block"] = "%#VisualMode#", + ["Select"] = "%#NormalMode#", + ["S-Line"] = "%#NormalMode#", + ["S-Block"] = "%#NormalMode#", + ["Insert"] = "%#InsertMode#", + ["Replace"] = "%#ReplaceMode#", + ["Command"] = "%#CommandMode#", + ["Prompt"] = "%#NormalMode#", + ["Shell"] = "%#NormalMode#", + ["Terminal"] = "%#NormalMode#", + ["None"] = "%#NormalMode#" + } + return color[m] end -- from https://github.com/nvim-lua/lsp-status.nvim/blob/master/lua/lsp-status/diagnostics.lua local function get_lsp_diagnostics(bufnr) - local result = {} - local levels = { - errors = "Error", - warnings = "Warn", - info = "Info", - hints = "Hint" - } + local result = {} + local levels = { + errors = "Error", + warnings = "Warn", + info = "Info", + hints = "Hint" + } - for k, level in pairs(levels) do - local count = 0 - local diags = vim.diagnostic.get(bufnr, { severity = level }) - for _, _ in pairs(diags) do - count = count + 1 - end - result[k] = count + for k, level in pairs(levels) do + local count = 0 + local diags = vim.diagnostic.get(bufnr, { severity = level }) + for _, _ in pairs(diags) do + count = count + 1 end + result[k] = count + end - return result + return result end local function process_diagnostics(prefix, n, hl) - if n > 0 then - return hl .. prefix .. n - else - return "" - end +if n > 0 then + return hl .. prefix .. n +else + return "" +end end local function spell_check() - if vim.wo.spell then - local lang = vim.o.spelllang - return "[SPELL=" .. lang .. "]" - else - return "" - end +if vim.wo.spell then + local lang = vim.o.spelllang + return "[SPELL=" .. lang .. "]" +else + return "" +end end local function statusline_focused() - local diagnostics = get_lsp_diagnostics() - local mode = vim.fn.mode() - local mg = get_mode(mode) - local accent_color = get_mode_color(mg) +local diagnostics = get_lsp_diagnostics() +local mode = vim.fn.mode() +local mg = get_mode(mode) +local accent_color = get_mode_color(mg) - local left = table.concat { - gen_section(accent_color, {get_mode_display_name(mg)}), - gen_section("%#Middle#", {"%f"}), - gen_section("%#Bottom#", {"%m", "%r"}), - gen_section( - "%#Alert#", - { - process_diagnostics( - globals.sign_error .. " ", - diagnostics.errors, - "%#DiagnosticVirtualTextError#" - ), - process_diagnostics( - globals.sign_warning .. " ", - diagnostics.warnings, - "%#DiagnosticVirtualTextWarn#" - ), - process_diagnostics( - globals.sign_info .. " ", - diagnostics.info, - "%#DiagnosticVirtualTextInfo#" - ) - } - ) +local left = table.concat { + gen_section(accent_color, {get_mode_display_name(mg)}), + gen_section("%#Middle#", {"%f"}), + gen_section("%#Bottom#", {"%m", "%r"}), + gen_section( + "%#Alert#", + { + process_diagnostics( + globals.sign_error .. " ", + diagnostics.errors, + "%#DiagnosticVirtualTextError#" + ), + process_diagnostics( + globals.sign_warning .. " ", + diagnostics.warnings, + "%#DiagnosticVirtualTextWarn#" + ), + process_diagnostics( + globals.sign_info .. " ", + diagnostics.info, + "%#DiagnosticVirtualTextInfo#" + ) } - local right = table.concat { - gen_section( - "%#Bottom#", - { - spell_check(), - vim.bo.filetype - } - ), - gen_section("%#Middle#", {"%03.p%%"}), - gen_section("%#Top#", {"-%03.c-"}) + ) +} +local right = table.concat { + gen_section( + "%#Bottom#", + { + spell_check(), + vim.bo.filetype } + ), + gen_section("%#Middle#", {"%03.p%%"}), + gen_section("%#Top#", {"-%03.c-"}) +} - return table.concat { - left, - "%#Statusline#", - "%=", - right - } +return table.concat { + left, + "%#Statusline#", + "%=", + right +} end local function statusline_not_focused() - return table.concat { - gen_section("%#StatuslineNF#", {"%f", "%m"}), - "%=", - gen_section("%#StatuslineNF#", {"%03.p%%"}), - gen_section("%#StatuslineNF#", {"-%03.c-"}) - } + return table.concat { + gen_section("%#StatuslineNF#", {"%f", "%m"}), + "%=", + gen_section("%#StatuslineNF#", {"%03.p%%"}), + gen_section("%#StatuslineNF#", {"-%03.c-"}) + } end function _G.gen_statusline() - if vim.g.statusline_winid == vim.fn.win_getid() then - return statusline_focused() - else - return statusline_not_focused() - end + if vim.g.statusline_winid == vim.fn.win_getid() then + return statusline_focused() + else + return statusline_not_focused() + end end vim.o.statusline = "%!luaeval(\"gen_statusline()\")"