From 77f5dd9693576af7fde80bdc99700f21eff01d6b Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Wed, 9 Feb 2022 17:53:48 +0100 Subject: WIP moving to all lua and new structure --- after/plugin/colors.lua | 16 ++++++++ after/plugin/completition.lua | 96 +++++++++++++++++++++++++++++++++++++++++++ after/plugin/harpoon.lua | 14 +++++++ after/plugin/lsp.lua | 43 +++++++++++++++++++ after/plugin/lualine.lua | 36 ++++++++++++++++ after/plugin/luasnip.lua | 7 ++++ after/plugin/treesitter.lua | 64 +++++++++++++++++++++++++++++ 7 files changed, 276 insertions(+) create mode 100644 after/plugin/colors.lua create mode 100644 after/plugin/completition.lua create mode 100644 after/plugin/harpoon.lua create mode 100644 after/plugin/lsp.lua create mode 100644 after/plugin/lualine.lua create mode 100644 after/plugin/luasnip.lua create mode 100644 after/plugin/treesitter.lua (limited to 'after/plugin') diff --git a/after/plugin/colors.lua b/after/plugin/colors.lua new file mode 100644 index 0000000..d6d0d18 --- /dev/null +++ b/after/plugin/colors.lua @@ -0,0 +1,16 @@ +local Color, colors, Group, groups, styles = require('colorbuddy').setup() + +-- Use Color.new(, <#rrggbb>) to create new colors +-- They can be accessed through colors. +Color.new('background', '#282c34') +Color.new('red', '#cc6666') +Color.new('green', '#99cc99') +Color.new('yellow', '#f0c674') + +-- Define highlights in terms of `colors` and `groups` +Group.new('Comment' , colors.yellow , colors.background , styles.bold) +Group.new('Special' , groups.Comment , groups.Comment , groups.Comment) +Group.new('NonText' , groups.Comment , groups.Comment , groups.Comment) + +-- Define highlights in relative terms of other colors +Group.new('Error' , colors.red:light() , nil , styles.bold) diff --git a/after/plugin/completition.lua b/after/plugin/completition.lua new file mode 100644 index 0000000..7140ca5 --- /dev/null +++ b/after/plugin/completition.lua @@ -0,0 +1,96 @@ +local lspkind = require "lspkind" + +local luasnip = require("luasnip") +local cmp = require "cmp" +local cmp_autopairs = require('nvim-autopairs.completion.cmp') +cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) + +cmp.setup { + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.close() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.choice_active() then + luasnip.change_choice(1) + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + [""] = cmp.mapping.complete(), + }, + sources = { + { name = "nvim_lua" }, + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { + name = "buffer", + keyword_length = 5, + option = { + get_bufnrs = function() + local bufs = {} + for _, win in ipairs(vim.api.nvim_list_wins()) do + bufs[vim.api.nvim_win_get_buf(win)] = true + end + return vim.tbl_keys(bufs) + end + } + }, + }, + + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + + formatting = { + format = lspkind.cmp_format { + with_text = true, + menu = { + buffer = "[buf]", + nvim_lsp = "[LSP]", + nvim_lua = "[api]", + path = "[path]", + luasnip = "[snip]", + } + } + }, + + experimental = { + native_menu = false, + + ghost_text = true, + } +} +-- Setup lspconfig. + local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + -- Replace with each lsp server you've enabled. + require('lspconfig')['emmet_ls'].setup { + capabilities = capabilities + } + +local Group = require("colorbuddy.group").Group +local g = require("colorbuddy.group").groups +local s = require("colorbuddy.style").styles + +Group.new("CmpItemAbbr", g.Comment) +Group.new("CmpItemAbbrDeprecated", g.Error) +Group.new("CmpItemAbbrMatchFuzzy", g.CmpItemAbbr.fg:dark(), nil, s.italic) +Group.new("CmpItemKind", g.Special) +Group.new("CmpItemMenu", g.NonText) diff --git a/after/plugin/harpoon.lua b/after/plugin/harpoon.lua new file mode 100644 index 0000000..087b29f --- /dev/null +++ b/after/plugin/harpoon.lua @@ -0,0 +1,14 @@ +local ok, harpoon = pcall(require, "harpoon") +if not ok then + return +end + +harpoon.setup {} + +vim.api.nvim_set_keymap("n", "ss", [[ lua require("harpoon.ui").toggle_quick_menu()]], {noremap = true, silent = true, expr = false}) + +vim.api.nvim_set_keymap("n", "sa", [[ lua require("harpoon.mark").add_file()]], {noremap = true, silent = true, expr = false}) +vim.api.nvim_set_keymap("n", "su", [[ lua require("harpoon.ui").nav_file(1)]], {noremap = true, silent = true, expr = false}) +vim.api.nvim_set_keymap("n", "si", [[ lua require("harpoon.ui").nav_file(2)]], {noremap = true, silent = true, expr = false}) +vim.api.nvim_set_keymap("n", "so", [[ lua require("harpoon.ui").nav_file(3)]], {noremap = true, silent = true, expr = false}) +vim.api.nvim_set_keymap("n", "sp", [[ lua require("harpoon.ui").nav_file(4)]], {noremap = true, silent = true, expr = false}) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua new file mode 100644 index 0000000..40a56d6 --- /dev/null +++ b/after/plugin/lsp.lua @@ -0,0 +1,43 @@ +local function on_attach() + -- keymaps for lsp + vim.api.nvim_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()', {noremap = true}) + vim.api.nvim_set_keymap('n', 'vd', ':lua vim.lsp.buf.definition()', {noremap = true}) + + + vim.api.nvim_set_keymap('n', 'vo', ':LspRestart', {noremap = true}) + + -- diagnostics to move between info and errors + vim.api.nvim_set_keymap('n', 'vn', ':lua vim.lsp.diagnostic.goto_next()', {noremap = true}) + vim.api.nvim_set_keymap('n', 'vp', ':lua vim.lsp.diagnostic.goto_prev()', {noremap = true}) + + + vim.api.nvim_set_keymap('n', 'vca', ':lua vim.lsp.buf.code_action()', {noremap = true}) + vim.api.nvim_set_keymap('n', 'vf', ':lua vim.lsp.buf.formatting()', {noremap = true}) + + vim.api.nvim_set_keymap('n', 'vi', ':lua vim.lsp.buf.implementation()', {noremap = true}) + vim.api.nvim_set_keymap('n', 'vrn', ':lua vim.lsp.buf.rename()', {noremap = true}) + + require "lsp_signature".on_attach() + + vim.cmd [[au Filetype php setl omnifunc=v:lua.vim.lsp.omnifunc]] + vim.cmd [[autocmd FileType go setlocal omnifunc=v:lua.vim.lsp.omnifunc]] + + vim.g.completion_matching_strategy_list = { 'exact', 'substring', 'fuzzy' } + +end + +local lsp_installer = require("nvim-lsp-installer") + +lsp_installer.on_server_ready(function(server) + local opts = {} + + -- (optional) Customize the options passed to the server + if server.name == "emmet_ls" then + opts.filetypes = {"html", "css", "blade"} + end + + opts.on_attach = on_attach + -- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart) + server:setup(opts) + vim.cmd [[ do User LspAttachBuffers ]] +end) diff --git a/after/plugin/lualine.lua b/after/plugin/lualine.lua new file mode 100644 index 0000000..bfd449a --- /dev/null +++ b/after/plugin/lualine.lua @@ -0,0 +1,36 @@ +local ok, lualine = pcall(require, "lualine") +if not ok then + return +end + +lualine.setup{ + options = { + theme = 'dracula', + icons_enabled = true, + }, + extensions = {'quickfix', 'fugitive'}, + sections = { + lualine_a = { { 'mode', upper = true } }, + lualine_b = { { 'branch', icon = '' }, 'diff' }, + lualine_c = { { 'filename', file_status = true, path = 1 } }, + lualine_x = { { 'diagnostics', sources = { 'nvim_diagnostic' } },'encoding', 'fileformat', 'filetype' }, + lualine_y = { 'progress' }, + lualine_z = { 'location' }, + }, + inactive_sections = { + lualine_a = { }, + lualine_b = { }, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = { }, + lualine_z = { }, + }, + -- tabline = { + -- lualine_a = {'buffers'}, + -- lualine_b = {}, + -- lualine_c = {}, + -- lualine_x = {}, + -- lualine_y = {}, + -- lualine_z = {'tabs'} + -- } + } diff --git a/after/plugin/luasnip.lua b/after/plugin/luasnip.lua new file mode 100644 index 0000000..9a1c3db --- /dev/null +++ b/after/plugin/luasnip.lua @@ -0,0 +1,7 @@ +if vim.g.snippets ~= "luasnip" then + return +end + + +-- shorcut to source my luasnips file again, which will reload my snippets +vim.keymap.set("n", "s", "source ~/.config/nvim/after/plugin/luasnip.lua") diff --git a/after/plugin/treesitter.lua b/after/plugin/treesitter.lua new file mode 100644 index 0000000..f2f5360 --- /dev/null +++ b/after/plugin/treesitter.lua @@ -0,0 +1,64 @@ +if not pcall(require, "nvim-treesitter") then + return +end + +require "nvim-treesitter.configs".setup { + ensure_installed = {"php", "go", "comment", "css", "html", "javascript", "lua", "typescript"}, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + indent = { + enable = true, + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", + node_incremental = "grn", + scope_incremental = "grc", + node_decremental = "grm", + }, + }, + refactor = { + highlight_definitions = { enable = true }, + smart_rename = { + enable = true, + keymaps = { + smart_rename = "grr", + }, + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@conditional.outer", + ["ic"] = "@conditional.inner", + ["al"] = "@loop.outer", + ["il"] = "@loop.inner", + } + } + }, + playground = { + enable = true, + disable = {}, + updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code + persist_queries = false, -- Whether the query persists across vim sessions + keybindings = { + toggle_query_editor = 'o', + toggle_hl_groups = 'i', + toggle_injected_languages = 't', + toggle_anonymous_nodes = 'a', + toggle_language_display = 'I', + focus_language = 'f', + unfocus_language = 'F', + update = 'R', + goto_node = '', + show_help = '?', + }, + } +} -- cgit v1.2.3