From 34da568c873cab5ce6e424b4393bbadd69dff666 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Mon, 18 Sep 2023 12:44:13 -0400 Subject: [PATCH] Initial migrations to lazy.nvim --- nvim/init.lua | 2 +- nvim/lua/config/cmp.lua | 230 ++++++++++++----------- nvim/lua/config/init.lua | 105 +++++++++++ nvim/lua/config/lsp-installer.lua | 22 +-- nvim/lua/config/lspconfig.lua | 158 ++++++++++++++++ nvim/lua/config/neo-tree.lua | 16 ++ nvim/lua/config/telescope.lua | 136 +++++++------- nvim/lua/config/tmp/cmp.lua | 118 ++++++++++++ nvim/lua/config/{ => tmp}/colorizer.lua | 0 nvim/lua/config/{ => tmp}/diffview.lua | 0 nvim/lua/config/tmp/lsp-installer.lua | 16 ++ nvim/lua/config/{ => tmp}/lsp.lua | 0 nvim/lua/config/{ => tmp}/lualine.lua | 0 nvim/lua/config/{ => tmp}/neogit.lua | 0 nvim/lua/config/{ => tmp}/nightfox.lua | 0 nvim/lua/config/{ => tmp}/nvim-tree.lua | 2 +- nvim/lua/config/tmp/telescope.lua | 66 +++++++ nvim/lua/config/{ => tmp}/treesitter.lua | 0 nvim/lua/config/{ => tmp}/vsnip.lua | 0 nvim/lua/config/{ => tmp}/which.lua | 0 nvim/lua/config/which-key.lua | 8 + nvim/lua/mappings.lua | 7 +- nvim/lua/plugins.lua | 129 ++----------- 23 files changed, 706 insertions(+), 309 deletions(-) create mode 100644 nvim/lua/config/init.lua create mode 100644 nvim/lua/config/lspconfig.lua create mode 100644 nvim/lua/config/neo-tree.lua create mode 100644 nvim/lua/config/tmp/cmp.lua rename nvim/lua/config/{ => tmp}/colorizer.lua (100%) rename nvim/lua/config/{ => tmp}/diffview.lua (100%) create mode 100644 nvim/lua/config/tmp/lsp-installer.lua rename nvim/lua/config/{ => tmp}/lsp.lua (100%) rename nvim/lua/config/{ => tmp}/lualine.lua (100%) rename nvim/lua/config/{ => tmp}/neogit.lua (100%) rename nvim/lua/config/{ => tmp}/nightfox.lua (100%) rename nvim/lua/config/{ => tmp}/nvim-tree.lua (99%) create mode 100644 nvim/lua/config/tmp/telescope.lua rename nvim/lua/config/{ => tmp}/treesitter.lua (100%) rename nvim/lua/config/{ => tmp}/vsnip.lua (100%) rename nvim/lua/config/{ => tmp}/which.lua (100%) create mode 100644 nvim/lua/config/which-key.lua diff --git a/nvim/init.lua b/nvim/init.lua index d626365..f71bb60 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,4 +1,4 @@ --- Plugins + require('plugins') -- Key maps diff --git a/nvim/lua/config/cmp.lua b/nvim/lua/config/cmp.lua index dee0ad5..0c3fdca 100644 --- a/nvim/lua/config/cmp.lua +++ b/nvim/lua/config/cmp.lua @@ -1,118 +1,134 @@ --- Setup nvim-cmp. -local cmp = require "cmp" -local lspkind = require("lspkind") -local capabilities = require('cmp_nvim_lsp').default_capabilities() +return { + "hrsh7th/nvim-cmp", + enabled = true, + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "hrsh7th/cmp-vsnip", + "f3fora/cmp-spell", + "hrsh7th/cmp-calc", + "hrsh7th/cmp-emoji" + }, + config = function() + -- Setup nvim-cmp. + local cmp = require "cmp" + local lspkind = require("lspkind") + local capabilities = require('cmp_nvim_lsp').default_capabilities() -local has_words_before = 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 -end + local has_words_before = 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 + end -local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), - mode, true) -end + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), + mode, true) + end -require'lspconfig'.sourcekit.setup { - capabilities = capabilities -} - -lspkind.init({ - symbol_map = { - Text = "", - Method = "", - Function = "", - Constructor = "", - Field = "ﰠ", - Variable = "", - Class = "ﴯ", - Interface = "", - Module = "", - Property = "ﰠ", - Unit = "塞", - Value = "", - Enum = "", - Keyword = "", - Snippet = "", - Color = "", - File = "", - Reference = "", - Folder = "", - EnumMember = "", - Constant = "", - Struct = "פּ", - Event = "", - Operator = "", - TypeParameter = "" + require('lspconfig').sourcekit.setup { + capabilities = capabilities } -}) -cmp.setup({ - formatting = { - format = lspkind.cmp_format { - with_text = false, - maxwidth = 50, - menu = { - buffer = "BUF", - nvim_lsp = "LSP", - path = "PATH", - vsnip = "SNIP", - calc = "CALC", - spell = "SPELL", - emoji = "EMOJI" - } + lspkind.init({ + symbol_map = { + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "ﰠ", + Variable = "", + Class = "ﴯ", + Interface = "", + Module = "", + Property = "ﰠ", + Unit = "塞", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "פּ", + Event = "", + Operator = "", + TypeParameter = "" } - }, - experimental = {native_menu = false, ghost_text = false}, - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - end - }, - mapping = { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = false + }) + + cmp.setup({ + formatting = { + format = lspkind.cmp_format { + with_text = false, + maxwidth = 50, + menu = { + buffer = "BUF", + nvim_lsp = "LSP", + path = "PATH", + vsnip = "SNIP", + calc = "CALC", + spell = "SPELL", + emoji = "EMOJI" + } + } }, - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif vim.fn["vsnip#available"](1) == 1 then - feedkey("(vsnip-expand-or-jump)", "") - elseif has_words_before() then - cmp.complete() - else - fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + experimental = {native_menu = false, ghost_text = false}, + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. end - end, {"i", "s"}), - [""] = cmp.mapping(function() - if cmp.visible() then - cmp.select_prev_item() - elseif vim.fn["vsnip#jumpable"](-1) == 1 then - feedkey("(vsnip-jump-prev)", "") - end - end, {"i", "s"}) - }, - sources = { - {name = "nvim_lsp"}, {name = "buffer", keyword_length = 5}, - {name = "vsnip"}, {name = "calc"}, {name = "emoji"}, {name = "spell"}, - {name = "path"} - } -}) + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = false + }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, {"i", "s"}), + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, {"i", "s"}) + }, + sources = { + {name = "nvim_lsp"}, {name = "buffer", keyword_length = 5}, + {name = "vsnip"}, {name = "calc"}, {name = "emoji"}, {name = "spell"}, + {name = "path"} + } + }) --- Use buffer source for `/`. -cmp.setup.cmdline("/", {sources = {{name = "buffer"}}}) + -- Use buffer source for `/`. + cmp.setup.cmdline("/", {sources = {{name = "buffer"}}}) --- Use cmdline & path source for ':'. -cmp.setup.cmdline(":", { - sources = cmp.config.sources({{name = "path"}}, {{name = "cmdline"}}) -}) + -- Use cmdline & path source for ':'. + cmp.setup.cmdline(":", { + sources = cmp.config.sources({{name = "path"}}, {{name = "cmdline"}}) + }) + end + } diff --git a/nvim/lua/config/init.lua b/nvim/lua/config/init.lua new file mode 100644 index 0000000..012dc3f --- /dev/null +++ b/nvim/lua/config/init.lua @@ -0,0 +1,105 @@ +return { + + -- Theme + { + 'EdenEast/nightfox.nvim', + lazy = false, -- make sure we load this during startup + priority = 1000, -- make sure to load this before all other plugins. + config = function() + -- load the colorscheme + vim.cmd([[colorscheme nightfox]]) + end, + --config = get_config("nightfox") + }, + { + "nvim-lualine/lualine.nvim", + dependencies = { + -- "nvim-tree/web-dev-icons" + }, + config = function() + --require('lau + end, + }, + + { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }, + + { + "nvim-treesitter/nvim-treesitter", + -- config = get_config("treesitter"), + -- run = ":TSUpdate" + }, + + "nvim-treesitter/nvim-treesitter-textobjects", + + + -- LSP + { + "onsails/lspkind-nvim", + dependencies = { + "famiu/bufdelete.nvim" + } + }, + { + "ray-x/lsp_signature.nvim", + dependencies = { + "neovim/nvim-lspconfig" + } + }, + + { "williamboman/mason.nvim" }, + { + "williamboman/mason-lspconfig.nvim", + config = function() + require('mason').setup() + require('mason-lspconfig').setup({ + ensure_installed = { + "bashls", + "clangd", + "dockerls", + "gopls", + "jsonls", + "jedi_language_server", + "lua_ls", + "terraformls", + "tsserver", + "texlab", + "yamlls", + } + }) + end + }, + + -- requirement for Neogit + { + "sindrets/diffview.nvim", + cmd = { + "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", + "DiffviewFocusFiles" + }, + --config = get_config("diffview") + }, + + { + "TimUntersberger/neogit", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope.nvim", -- optional + "sindrets/diffview.nvim", -- optional + }, + cmd = "Neogit", + --config = get_config("neogit") + }, + + { + "hrsh7th/vim-vsnip", + --config = get_config("vsnip") + }, + +-- use({ +-- "andrewferrier/wrapping.nvim", +-- config = function() +-- require("wrapping").setup() +-- end, +-- }) + +} diff --git a/nvim/lua/config/lsp-installer.lua b/nvim/lua/config/lsp-installer.lua index 43dccc9..745a7df 100644 --- a/nvim/lua/config/lsp-installer.lua +++ b/nvim/lua/config/lsp-installer.lua @@ -1,16 +1,6 @@ -local lsp_installer = require("nvim-lsp-installer") - --- Register a handler that will be called for all installed servers. --- Alternatively, you may also register handlers on specific server instances instead (see example below). -lsp_installer.on_server_ready(function(server) - local opts = {} - - -- (optional) Customize the options passed to the server - -- if server.name == "tsserver" then - -- opts.root_dir = function() ... end - -- end - - -- This setup() function is exactly the same as lspconfig's setup function. - -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md - server:setup(opts) -end) +return { + "williamboman/nvim-lsp-installer", + config = function() + require("nvim-lsp-installer").setup() + end +} diff --git a/nvim/lua/config/lspconfig.lua b/nvim/lua/config/lspconfig.lua new file mode 100644 index 0000000..fe4d632 --- /dev/null +++ b/nvim/lua/config/lspconfig.lua @@ -0,0 +1,158 @@ +return { + "neovim/nvim-lspconfig", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + }, + config = function() + require("mason").setup() + require("mason-lspconfig").setup() + local nvim_lsp = require("lspconfig") + + -- Use an on_attach function to only map the following keys + -- after the language server attaches to the current buffer + local on_attach = function(bufnr) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + + -- Mappings. + local opts = {noremap = true, silent = true} + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) + buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) + buf_set_keymap("n", "gT", vim.lsp.buf.type_definition, opts) + -- buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap("n", "wa", + "lua vim.lsp.buf.add_workspace_folder()", opts) + buf_set_keymap("n", "wr", + "lua vim.lsp.buf.remove_workspace_folder()", opts) + buf_set_keymap("n", "wl", + "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", + opts) + buf_set_keymap("n", "D", + "lua vim.lsp.buf.type_definition()", opts) + buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) + buf_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", + opts) + buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) + buf_set_keymap("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) + buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) + + buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) + buf_set_keymap("n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) + buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) + + end + + -- Use a loop to conveniently call 'setup' on multiple servers and + -- map buffer local keybindings when the language server attaches + --local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require("cmp_nvim_lsp").default_capabilities() + + local servers = { + "gopls", "bashls", "jedi_language_server", "dockerls", "terraformls", + "tsserver", "texlab", "yamlls", "jsonls", "clangd", "sourcekit" + } + for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + settings = { + gopls = {analyses = {unusedparams = false}, staticcheck = true}, + json = { + format = {enabled = false}, + schemas = { + { + description = "ESLint config", + fileMatch = {".eslintrc.json", ".eslintrc"}, + url = "http://json.schemastore.org/eslintrc" + }, { + description = "Package config", + fileMatch = {"package.json"}, + url = "https://json.schemastore.org/package" + }, { + description = "Packer config", + fileMatch = {"packer.json"}, + url = "https://json.schemastore.org/packer" + }, { + description = "Renovate config", + fileMatch = { + "renovate.json", "renovate.json5", + ".github/renovate.json", ".github/renovate.json5", + ".renovaterc", ".renovaterc.json" + }, + url = "https://docs.renovatebot.com/renovate-schema" + }, { + description = "OpenApi config", + fileMatch = {"*api*.json"}, + url = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json" + } + } + }, + redhat = {telemetry = {enabled = false}}, + texlab = { + auxDirectory = ".", + bibtexFormatter = "texlab", + build = { + args = { + "--keep-intermediates", "--keep-logs", "--synctex", "%f" + }, + executable = "tectonic", + forwardSearchAfter = false, + onSave = false + }, + chktex = {onEdit = false, onOpenAndSave = false}, + diagnosticsDelay = 300, + formatterLineLength = 80, + forwardSearch = {args = {}}, + latexFormatter = "latexindent", + latexindent = {modifyLineBreaks = false} + }, + yaml = { + schemaStore = { + enable = true, + url = "https://www.schemastore.org/api/json/catalog.json" + }, + schemas = { + kubernetes = "/*.yaml", + ["http://json.schemastore.org/github-workflow"] = ".github/workflows/*.{yml,yaml}", + ["http://json.schemastore.org/github-action"] = ".github/action.{yml,yaml}", + ["http://json.schemastore.org/ansible-stable-2.9"] = "roles/tasks/*.{yml,yaml}", + ["http://json.schemastore.org/prettierrc"] = ".prettierrc.{yml,yaml}", + ["http://json.schemastore.org/kustomization"] = "kustomization.{yml,yaml}", + ["http://json.schemastore.org/ansible-playbook"] = "*play*.{yml,yaml}", + ["http://json.schemastore.org/chart"] = "Chart.{yml,yaml}", + ["https://json.schemastore.org/dependabot-v2"] = ".github/dependabot.{yml,yaml}", + ["https://json.schemastore.org/gitlab-ci"] = "*gitlab-ci*.{yml,yaml}", + ["https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json"] = "*api*.{yml,yaml}", + ["https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"] = "docker-compose.{yml,yaml}", + ["https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json"] = "*flow*.{yml,yaml}" + }, + format = {enabled = false}, + validate = false, -- TODO: conflicts between Kubernetes resources and kustomization.yaml + completion = true, + hover = true + } + }, + flags = {debounce_text_changes = 150} + } + require"lsp_signature".setup({ + bind = true, -- This is mandatory, otherwise border config won't get registered. + floating_window = true, -- show hint in a floating window, set to false for virtual text only mode + doc_lines = 2, -- Set to 0 for not showing doc + hint_prefix = "🐼 ", + -- use_lspsaga = false, -- set to true if you want to use lspsaga popup + handler_opts = { + border = "shadow" -- double, single, shadow, none + } + }) + end + + -- Test source-kit + require('lspconfig').sourcekit.setup{} + + end +} diff --git a/nvim/lua/config/neo-tree.lua b/nvim/lua/config/neo-tree.lua new file mode 100644 index 0000000..a7c6f54 --- /dev/null +++ b/nvim/lua/config/neo-tree.lua @@ -0,0 +1,16 @@ +return { + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + }, + config = function() + require("neo-tree").setup({ + close_if_last_window = false, + enable_git_status = true, + enable_diagnostics = true + }) + end +} diff --git a/nvim/lua/config/telescope.lua b/nvim/lua/config/telescope.lua index bf02448..6062dfa 100644 --- a/nvim/lua/config/telescope.lua +++ b/nvim/lua/config/telescope.lua @@ -1,66 +1,76 @@ -local actions = require('telescope.actions') -local telescope = require('telescope') +return { + 'nvim-telescope/telescope.nvim', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim' + }, + config = function() + require('telescope').setup({ + defaults = { + file_ignore_patterns = {"node_modules", "%.jpg", "%.png"}, + vimgrep_arguments = { + 'rg', + '--follow', + '--color=never', + '--no-heading', + '--with-filename', + '--line-number', + '--column', + '--smart-case' + }, +-- mappings = { +-- i = { +-- -- Close on first esc instead of gonig to normal mode +-- [""] = actions.close, +-- [""] = actions.send_selected_to_qflist, +-- [""] = actions.send_to_qflist, +-- [""] = actions.toggle_selection + actions.move_selection_next, +-- [""] = actions.toggle_selection + actions.move_selection_previous, +-- }, +-- n = { +-- [""] = actions.toggle_selection + actions.move_selection_next, +-- [""] = actions.toggle_selection + actions.move_selection_previous, +-- [""] = actions.send_selected_to_qflist, +-- [""] = actions.send_to_qflist, +-- }, +-- }, + prompt_prefix = " ", + selection_caret = " ", + entry_prefix = " ", + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = "descending", + layout_strategy = "flex", + layout_config = { + width = 0.75, + prompt_position = "bottom", + preview_cutoff = 120, + horizontal = { mirror = false }, + vertical = { mirror = true }, + }, + file_sorter = require'telescope.sorters'.get_fuzzy_file, + generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter, + -- path_display = true, -- strange behaviour not showing the files in result window + winblend = 0, + border = {}, + borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' }, + color_devicons = true, + use_less = true, + set_env = { ['COLORTERM'] = 'truecolor' }, -- default = nil, + file_previewer = require'telescope.previewers'.vim_buffer_cat.new, + grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new, + qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new, ---telescope.load_extension('projects') -telescope.load_extension('fzf') + -- Developer configurations: Not meant for general override + buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker + } + }) -telescope.setup{ - defaults = { - file_ignore_patterns = {"node_modules", "%.jpg", "%.png"}, - vimgrep_arguments = { - 'rg', - '--follow', - '--color=never', - '--no-heading', - '--with-filename', - '--line-number', - '--column', - '--smart-case' - }, - mappings = { - i = { - -- Close on first esc instead of gonig to normal mode - [""] = actions.close, - [""] = actions.send_selected_to_qflist, - [""] = actions.send_to_qflist, - [""] = actions.toggle_selection + actions.move_selection_next, - [""] = actions.toggle_selection + actions.move_selection_previous, - }, - n = { - [""] = actions.toggle_selection + actions.move_selection_next, - [""] = actions.toggle_selection + actions.move_selection_previous, - [""] = actions.send_selected_to_qflist, - [""] = actions.send_to_qflist, - }, - }, - prompt_prefix = " ", - selection_caret = " ", - entry_prefix = " ", - initial_mode = "insert", - selection_strategy = "reset", - sorting_strategy = "descending", - layout_strategy = "flex", - layout_config = { - width = 0.75, - prompt_position = "bottom", - preview_cutoff = 120, - horizontal = { mirror = false }, - vertical = { mirror = true }, - }, - file_sorter = require'telescope.sorters'.get_fuzzy_file, - generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter, - -- path_display = true, -- strange behaviour not showing the files in result window - winblend = 0, - border = {}, - borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' }, - color_devicons = true, - use_less = true, - set_env = { ['COLORTERM'] = 'truecolor' }, -- default = nil, - file_previewer = require'telescope.previewers'.vim_buffer_cat.new, - grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new, - qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new, - - -- Developer configurations: Not meant for general override - buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker - } + local builtin = require('telescope.builtin') + -- Telescope keymaps + vim.keymap.set('n', 'ff', builtin.find_files, {}) + vim.keymap.set('n', 'fg', builtin.live_grep, {}) + vim.keymap.set('n', 'fb', builtin.buffers, {}) + vim.keymap.set('n', 'fh', builtin.help_tags, {}) + end } diff --git a/nvim/lua/config/tmp/cmp.lua b/nvim/lua/config/tmp/cmp.lua new file mode 100644 index 0000000..dee0ad5 --- /dev/null +++ b/nvim/lua/config/tmp/cmp.lua @@ -0,0 +1,118 @@ +-- Setup nvim-cmp. +local cmp = require "cmp" +local lspkind = require("lspkind") +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +local has_words_before = 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 +end + +local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), + mode, true) +end + + +require'lspconfig'.sourcekit.setup { + capabilities = capabilities +} + +lspkind.init({ + symbol_map = { + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "ﰠ", + Variable = "", + Class = "ﴯ", + Interface = "", + Module = "", + Property = "ﰠ", + Unit = "塞", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "פּ", + Event = "", + Operator = "", + TypeParameter = "" + } +}) + +cmp.setup({ + formatting = { + format = lspkind.cmp_format { + with_text = false, + maxwidth = 50, + menu = { + buffer = "BUF", + nvim_lsp = "LSP", + path = "PATH", + vsnip = "SNIP", + calc = "CALC", + spell = "SPELL", + emoji = "EMOJI" + } + } + }, + experimental = {native_menu = false, ghost_text = false}, + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + end + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = false + }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, {"i", "s"}), + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, {"i", "s"}) + }, + sources = { + {name = "nvim_lsp"}, {name = "buffer", keyword_length = 5}, + {name = "vsnip"}, {name = "calc"}, {name = "emoji"}, {name = "spell"}, + {name = "path"} + } +}) + +-- Use buffer source for `/`. +cmp.setup.cmdline("/", {sources = {{name = "buffer"}}}) + +-- Use cmdline & path source for ':'. +cmp.setup.cmdline(":", { + sources = cmp.config.sources({{name = "path"}}, {{name = "cmdline"}}) +}) diff --git a/nvim/lua/config/colorizer.lua b/nvim/lua/config/tmp/colorizer.lua similarity index 100% rename from nvim/lua/config/colorizer.lua rename to nvim/lua/config/tmp/colorizer.lua diff --git a/nvim/lua/config/diffview.lua b/nvim/lua/config/tmp/diffview.lua similarity index 100% rename from nvim/lua/config/diffview.lua rename to nvim/lua/config/tmp/diffview.lua diff --git a/nvim/lua/config/tmp/lsp-installer.lua b/nvim/lua/config/tmp/lsp-installer.lua new file mode 100644 index 0000000..43dccc9 --- /dev/null +++ b/nvim/lua/config/tmp/lsp-installer.lua @@ -0,0 +1,16 @@ +local lsp_installer = require("nvim-lsp-installer") + +-- Register a handler that will be called for all installed servers. +-- Alternatively, you may also register handlers on specific server instances instead (see example below). +lsp_installer.on_server_ready(function(server) + local opts = {} + + -- (optional) Customize the options passed to the server + -- if server.name == "tsserver" then + -- opts.root_dir = function() ... end + -- end + + -- This setup() function is exactly the same as lspconfig's setup function. + -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md + server:setup(opts) +end) diff --git a/nvim/lua/config/lsp.lua b/nvim/lua/config/tmp/lsp.lua similarity index 100% rename from nvim/lua/config/lsp.lua rename to nvim/lua/config/tmp/lsp.lua diff --git a/nvim/lua/config/lualine.lua b/nvim/lua/config/tmp/lualine.lua similarity index 100% rename from nvim/lua/config/lualine.lua rename to nvim/lua/config/tmp/lualine.lua diff --git a/nvim/lua/config/neogit.lua b/nvim/lua/config/tmp/neogit.lua similarity index 100% rename from nvim/lua/config/neogit.lua rename to nvim/lua/config/tmp/neogit.lua diff --git a/nvim/lua/config/nightfox.lua b/nvim/lua/config/tmp/nightfox.lua similarity index 100% rename from nvim/lua/config/nightfox.lua rename to nvim/lua/config/tmp/nightfox.lua diff --git a/nvim/lua/config/nvim-tree.lua b/nvim/lua/config/tmp/nvim-tree.lua similarity index 99% rename from nvim/lua/config/nvim-tree.lua rename to nvim/lua/config/tmp/nvim-tree.lua index ff509a5..c36c90c 100644 --- a/nvim/lua/config/nvim-tree.lua +++ b/nvim/lua/config/tmp/nvim-tree.lua @@ -34,7 +34,7 @@ g.nvim_tree_icons = { } g.loaded_netrw = 1 g.loaded_netrwPlugin = 1 -local tree_cb = require"nvim-tree.config".nvim_tree_callback +local tree_cb = require("nvim-tree.config").nvim_tree_callback -- This function has been generated from your -- view.mappings.list diff --git a/nvim/lua/config/tmp/telescope.lua b/nvim/lua/config/tmp/telescope.lua new file mode 100644 index 0000000..bf02448 --- /dev/null +++ b/nvim/lua/config/tmp/telescope.lua @@ -0,0 +1,66 @@ +local actions = require('telescope.actions') +local telescope = require('telescope') + +--telescope.load_extension('projects') +telescope.load_extension('fzf') + +telescope.setup{ + defaults = { + file_ignore_patterns = {"node_modules", "%.jpg", "%.png"}, + vimgrep_arguments = { + 'rg', + '--follow', + '--color=never', + '--no-heading', + '--with-filename', + '--line-number', + '--column', + '--smart-case' + }, + mappings = { + i = { + -- Close on first esc instead of gonig to normal mode + [""] = actions.close, + [""] = actions.send_selected_to_qflist, + [""] = actions.send_to_qflist, + [""] = actions.toggle_selection + actions.move_selection_next, + [""] = actions.toggle_selection + actions.move_selection_previous, + }, + n = { + [""] = actions.toggle_selection + actions.move_selection_next, + [""] = actions.toggle_selection + actions.move_selection_previous, + [""] = actions.send_selected_to_qflist, + [""] = actions.send_to_qflist, + }, + }, + prompt_prefix = " ", + selection_caret = " ", + entry_prefix = " ", + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = "descending", + layout_strategy = "flex", + layout_config = { + width = 0.75, + prompt_position = "bottom", + preview_cutoff = 120, + horizontal = { mirror = false }, + vertical = { mirror = true }, + }, + file_sorter = require'telescope.sorters'.get_fuzzy_file, + generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter, + -- path_display = true, -- strange behaviour not showing the files in result window + winblend = 0, + border = {}, + borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' }, + color_devicons = true, + use_less = true, + set_env = { ['COLORTERM'] = 'truecolor' }, -- default = nil, + file_previewer = require'telescope.previewers'.vim_buffer_cat.new, + grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new, + qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new, + + -- Developer configurations: Not meant for general override + buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker + } +} diff --git a/nvim/lua/config/treesitter.lua b/nvim/lua/config/tmp/treesitter.lua similarity index 100% rename from nvim/lua/config/treesitter.lua rename to nvim/lua/config/tmp/treesitter.lua diff --git a/nvim/lua/config/vsnip.lua b/nvim/lua/config/tmp/vsnip.lua similarity index 100% rename from nvim/lua/config/vsnip.lua rename to nvim/lua/config/tmp/vsnip.lua diff --git a/nvim/lua/config/which.lua b/nvim/lua/config/tmp/which.lua similarity index 100% rename from nvim/lua/config/which.lua rename to nvim/lua/config/tmp/which.lua diff --git a/nvim/lua/config/which-key.lua b/nvim/lua/config/which-key.lua new file mode 100644 index 0000000..3edd7ba --- /dev/null +++ b/nvim/lua/config/which-key.lua @@ -0,0 +1,8 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 300 + end, +} diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua index ec7b715..66069ea 100644 --- a/nvim/lua/mappings.lua +++ b/nvim/lua/mappings.lua @@ -2,10 +2,6 @@ local keymap = vim.api.nvim_set_keymap local default_options = {noremap = true, silent = true} -- local expr_options = {noremap = true, expr = true, silent = true} --- map the leader key -keymap('n', '', '', default_options) -vim.g.mapleader = " " - -- easier escape key mapping keymap('i', 'jk', '', default_options) @@ -32,4 +28,5 @@ keymap("x", "K", ":move '<-2gv-gv", default_options) keymap("x", "J", ":move '>+1gv-gv", default_options) -- Toggle nvim-tree open or closed -keymap("n", "", "NvimTreeToggle", default_options) +keymap("n", "", ":Neotree toggle", default_options) + diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 585647e..ac2bd47 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -1,121 +1,18 @@ -- Plugins - -local execute = vim.api.nvim_command -local fn = vim.fn -local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' - - --- returns the require for use in `config` parameter of packer's use --- expects the name of the config file -function get_config(name) - return string.format("require(\"config/%s\")", name) -end - --- Install packer if not available -if fn.empty(fn.glob(install_path)) > 0 then - fn.system({ - "git", "clone", "https://github.com/wbthomason/packer.nvim", - install_path +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", -- latest stable release + lazypath, }) - execute "packadd packer.nvim" end +vim.opt.rtp:prepend(lazypath) --- Initialize and configure packer -local packer = require("packer") -packer.init { - enable = true, -- enable profiling via :PackerCompile profile=true - threshold = 0 -- the amount in ms that a plugins load time must be over for it to be included in the profile -} -local use = packer.use -packer.reset() +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' --- actual plugins list -use "wbthomason/packer.nvim" - -use {"kyazdani42/nvim-tree.lua", config = get_config("nvim-tree")} - -use { - "nvim-lualine/lualine.nvim", - config = get_config("lualine"), - requires = {"kyazdani42/nvim-web-devicons", opt = true} -} - -use { - 'nvim-telescope/telescope.nvim', - config = get_config("telescope"), - requires = { {'nvim-lua/plenary.nvim'} } -} - -use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } - -use { - "nvim-treesitter/nvim-treesitter", - config = get_config("treesitter"), - run = ":TSUpdate" -} - -use "nvim-treesitter/nvim-treesitter-textobjects" - -use { - "hrsh7th/nvim-cmp", - requires = { - {"hrsh7th/cmp-nvim-lsp"}, {"hrsh7th/cmp-buffer"}, {"hrsh7th/cmp-path"}, - {"hrsh7th/cmp-cmdline"}, {"hrsh7th/cmp-vsnip"}, - {"f3fora/cmp-spell", {"hrsh7th/cmp-calc"}, {"hrsh7th/cmp-emoji"}} - }, - config = get_config("cmp") -} - -use {"onsails/lspkind-nvim", requires = {{"famiu/bufdelete.nvim"}}} - --- LSP -use {"ray-x/lsp_signature.nvim", requires = {{"neovim/nvim-lspconfig"}}} - -use { "williamboman/mason.nvim" } -use { "williamboman/mason-lspconfig.nvim" } -use { - "neovim/nvim-lspconfig", - config = get_config("lsp") -} -use { - "williamboman/nvim-lsp-installer", - config = get_config("lsp-installer") -} - -use {"folke/which-key.nvim", event = "VimEnter", config = get_config("which")} - --- requirement for Neogit -use { - "sindrets/diffview.nvim", - cmd = { - "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", - "DiffviewFocusFiles" - }, - config = get_config("diffview") -} - -use { - "TimUntersberger/neogit", - requires = { - "nvim-lua/plenary.nvim", - "nvim-telescope/telescope.nvim", -- optional - "sindrets/diffview.nvim", -- optional - }, - cmd = "Neogit", - config = get_config("neogit") -} - -use {"hrsh7th/vim-vsnip", config = get_config("vsnip")} - -use({ - "andrewferrier/wrapping.nvim", - config = function() - require("wrapping").setup() - end, -}) - --- Theme -use { - 'EdenEast/nightfox.nvim', - config = get_config("nightfox") -} +require("lazy").setup('config')