diff options
Diffstat (limited to 'lua')
-rw-r--r-- | lua/user/cmp.lua | 122 | ||||
-rw-r--r-- | lua/user/config.lua | 26 | ||||
-rw-r--r-- | lua/user/keymaps.lua | 50 | ||||
-rw-r--r-- | lua/user/lsp/handlers.lua | 89 | ||||
-rw-r--r-- | lua/user/lsp/init.lua | 8 | ||||
-rw-r--r-- | lua/user/lsp/lsp-installer.lua | 20 | ||||
-rw-r--r-- | lua/user/lsp/settings/sumneko_lua.lua | 15 | ||||
-rw-r--r-- | lua/user/lsp/test.py | 1 | ||||
-rw-r--r-- | lua/user/options.lua | 19 | ||||
-rw-r--r-- | lua/user/plugins.lua | 71 | ||||
-rw-r--r-- | lua/user/telescope.lua | 83 | ||||
-rw-r--r-- | lua/user/treesitter.lua | 16 | ||||
-rw-r--r-- | lua/user/vimplug.lua | 65 |
13 files changed, 585 insertions, 0 deletions
diff --git a/lua/user/cmp.lua b/lua/user/cmp.lua new file mode 100644 index 0000000..960eb13 --- /dev/null +++ b/lua/user/cmp.lua @@ -0,0 +1,122 @@ +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +local snip_status_ok, luasnip = pcall(require, "luasnip") +if not snip_status_ok then + return +end + +require("luasnip/loaders/from_vscode").lazy_load() + +local check_backspace = function() + local col = vim.fn.col "." - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +end + +local kind_icons = { + Text = "", + Method = "m", + 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({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = { + ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping. + ['<C-e>'] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + ['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + ["<Tab>"] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end, { + "i", + "s", + }), + ["<S-Tab>"] = 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", + }), + }, + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "nvim_lua" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }), + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + vim_item.menu = ({ + nvim_lsp = "[LSP]", + nvim_lua = "[NVIM_LUA]", + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + experimental = { + -- ghost_text = true, + }, +}) diff --git a/lua/user/config.lua b/lua/user/config.lua new file mode 100644 index 0000000..4f6b233 --- /dev/null +++ b/lua/user/config.lua @@ -0,0 +1,26 @@ +vim.cmd [[colorscheme gruvbox]] + +-- local Plug = require 'vimplug' + +-- Plug.begin('~/.config/share/nvim/plugged') +-- +-- Plug 'https://github.com/vim-airline/vim-airline' +-- Plug 'https://github.com/rafi/awesome-vim-colorschemes' +-- Plug 'https://github.com/preservim/nerdtree' +-- Plug 'https://github.com/neovim/nvim-lspconfig' +-- Plug 'https://github.com/williamboman/nvim-lsp-installer' +-- Plug 'https://github.com/hrsh7th/nvim-cmp' +-- Plug 'https://github.com/hrsh7th/cmp-nvim-lsp' +-- Plug 'https://github.com/hrsh7th/cmp-buffer' +-- Plug 'https://github.com/hrsh7th/cmp-path' +-- Plug 'https://github.com/hrsh7th/cmp-cmdline' +-- Plug 'https://github.com/hrsh7th/nvim-cmp' +-- Plug 'https://github.com/L3MON4D3/LuaSnip' +-- Plug 'https://github.com/rafamadriz/friendly-snippets' +-- Plug 'https://github.com/saadparwaiz1/cmp_luasnip' +-- Plug 'https://github.com/nvim-lua/popup.nvim' +-- Plug 'https://github.com/nvim-lua/plenary.nvim' +-- +-- Plug.ends() +-- +-- vim.cmd [[colorscheme gruvbox]] diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua new file mode 100644 index 0000000..3c5fc5b --- /dev/null +++ b/lua/user/keymaps.lua @@ -0,0 +1,50 @@ +local opts = { noremap = true, silent = true } + +local term_opts = { silent = true } + +local keymap = vim.api.nvim_set_keymap + +-- Better window navigation +keymap("n", "<C-h>", "<C-w>h", opts) +keymap("n", "<C-j>", "<C-w>j", opts) +keymap("n", "<C-k>", "<C-w>k", opts) +keymap("n", "<C-l>", "<C-w>l", opts) + + +-- Remap space as leader key +keymap("n", "<Space>", "<Nop>", opts) +vim.g.mapleader = " " +vim.g.maplocalleader = " " + + +-- NERDTree keybindings +keymap("n", "<C-n>", ":NERDTree<CR>", opts) +keymap("n", "<C-t>", ":NERDTreeToggle<CR>", opts) + +-- Resizing windows (like i3) +keymap("n", "<C-Up>", ":resize -2<CR>", opts) +keymap("n", "<C-Down>", ":resize +2<CR>", opts) +keymap("n", "<C-Left>", ":vertical resize -2<CR>", opts) +keymap("n", "<C-Right>", ":vertical resize +2<CR>", opts) + +-- Moving between buffers +keymap("n", "<S-l>", ":bnext<CR>", opts) +keymap("n", "<S-h>", ":bprevious<CR>", opts) + +-- Move text up and down +keymap("n", "<A-j>", "<Esc>:m .+1<CR>==", opts) +keymap("n", "<A-k>", "<Esc>:m .-2<CR>==", opts) + +-- Visual mode -- +keymap("v", "<", "<gv", opts) +keymap("v", ">", ">gv", opts) + +-- Move text up and down +keymap("v", "<A-j>", ":m .+1<CR>==", opts) +keymap("v", "<A-k>", ":m .-2<CR>==", opts) +keymap("v", "p", '"_dP', opts) + +-- Telescope +-- keymap("n", "<leader>f", "<cmd>lua require 'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({previewer = false}))<CR>", opts) +keymap("n", "<leader>f", "<cmd>Telescope find_files<CR>", opts) +-- keymap("n", "<C-t>", "<cmd>Telescope live_grep<CR>", opts) diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua new file mode 100644 index 0000000..f5ab1ed --- /dev/null +++ b/lua/user/lsp/handlers.lua @@ -0,0 +1,89 @@ +local M = {} + +M.setup = function() + local signs = { + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } + + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local config = { + virtual_text = false, + signs = { + active = signs, + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = false, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + + vim.diagnostic.config(config) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) +end + +local function lsp_keymaps(bufnr) + local function set_keymap(mode, shortcut, cmd, opts) + return vim.api.nvim_buf_set_keymap(bufnr, mode, shortcut, cmd, opts) + end + + local opts = { noremap = true, silent = true } + set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts) + set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts) + set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts) + set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) + set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts) + set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) + set_keymap("n", "[d", '<cmd>lua vim.diagnostic.goto_prev({border = "rounded"})<CR>', opts) + set_keymap("n", "gl", '<cmd>lua vim.diagnostic.open_float({border = "rounded"})<CR>', opts) + set_keymap("n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts) + + vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] +end + +local function lsp_highlight_document(client) + -- Set autocommands conditional on server_capabilities + if client.resolved_capabilities.document_highlight then + vim.api.nvim_exec( + [[ + augroup lsp_document_highlight + autocmd! * <buffer> + autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() + autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() + augroup END + ]], + false + ) + end +end + + +M.on_attach = function(client, bufnr) + lsp_keymaps(bufnr) + lsp_highlight_document(client) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() + +local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not status_ok then + return +end + +M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + +return M diff --git a/lua/user/lsp/init.lua b/lua/user/lsp/init.lua new file mode 100644 index 0000000..dd11327 --- /dev/null +++ b/lua/user/lsp/init.lua @@ -0,0 +1,8 @@ +local status_ok, _ = pcall(require, "lspconfig") +if not status_ok then + print "Lspconfig not opened correctly" + return +end + +require("user.lsp.lsp-installer") +require("user.lsp.handlers").setup() diff --git a/lua/user/lsp/lsp-installer.lua b/lua/user/lsp/lsp-installer.lua new file mode 100644 index 0000000..7ed988c --- /dev/null +++ b/lua/user/lsp/lsp-installer.lua @@ -0,0 +1,20 @@ +local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer") +if not status_ok then + print "nvim-lsp-installer not opened correctly" + return +end + + +lsp_installer.on_server_ready(function(server) + local opts = { + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + } + + if server.name == "sumneko_lua" then + local sumneko_opts = require("user.lsp.settings.sumneko_lua") + opts = vim.tbl_deep_extend("force", sumneko_opts, opts) + end + + server:setup(opts) +end) diff --git a/lua/user/lsp/settings/sumneko_lua.lua b/lua/user/lsp/settings/sumneko_lua.lua new file mode 100644 index 0000000..ea650f0 --- /dev/null +++ b/lua/user/lsp/settings/sumneko_lua.lua @@ -0,0 +1,15 @@ +return { + settings = { + Lua = { + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.expand("config") .. "/lua"] = true, + }, + }, + }, + }, +} diff --git a/lua/user/lsp/test.py b/lua/user/lsp/test.py new file mode 100644 index 0000000..2399fb2 --- /dev/null +++ b/lua/user/lsp/test.py @@ -0,0 +1 @@ +import math.sqrt diff --git a/lua/user/options.lua b/lua/user/options.lua new file mode 100644 index 0000000..293aa31 --- /dev/null +++ b/lua/user/options.lua @@ -0,0 +1,19 @@ +local options = { + completeopt = { "menuone", "noselect" }, + tabstop = 4, + shiftwidth = 2, + scrolloff = 5, + number = true, + relativenumber = true, + wrap = false, + cursorline = true, + numberwidth = 4, + undofile = true, +} + + +for k, v in pairs(options) do + vim.opt[k] = v +end + +vim.cmd [[set matchpairs+=<:>]] diff --git a/lua/user/plugins.lua b/lua/user/plugins.lua new file mode 100644 index 0000000..f07da22 --- /dev/null +++ b/lua/user/plugins.lua @@ -0,0 +1,71 @@ +local fn = vim.fn + +-- Automatically install pakcer +local install_path = fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim" +if fn.empty(fn.glob(install_path)) > 0 then + PACKER_BOOTSTRAP = fn.system { + "git", + "clone", + "--depth", + "1", + "https://github.com/wbthomason/packer.nvim", + install_path, + } + print "Installing packer close and reopen Neovim..." + vim.cmd [[packadd packer.nvim]] +end + +vim.cmd [[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source <afile> | PackerSync + augroup end +]] + +local status_ok, packer = pcall(require, "packer") +if not status_ok then + return +end + +packer.init { + display = { + open_fn = function() + return require("packer.util").float { border = "rounded" } + end, + }, +} + +return packer.startup(function(use) + use "wbthomason/packer.nvim" + use "nvim-lua/popup.nvim" + use "nvim-lua/plenary.nvim" + + use "vim-airline/vim-airline" + use "rafi/awesome-vim-colorschemes" + use "preservim/nerdtree" + + use 'hrsh7th/nvim-cmp' + use 'hrsh7th/cmp-nvim-lsp' + use 'hrsh7th/cmp-nvim-lua' + use 'hrsh7th/cmp-buffer' + use 'hrsh7th/cmp-path' + use 'hrsh7th/cmp-cmdline' + + use 'saadparwaiz1/cmp_luasnip' + use 'L3MON4D3/LuaSnip' + use 'rafamadriz/friendly-snippets' + + use 'neovim/nvim-lspconfig' + use 'williamboman/nvim-lsp-installer' + + use 'nvim-telescope/telescope.nvim' + use 'nvim-telescope/telescope-media-files.nvim' + + use { + 'nvim-treesitter/nvim-treesitter', + run = ":TSUpdate", + } + if PACKER_BOOTSTRAP then + require("packer").sync() + end +end) diff --git a/lua/user/telescope.lua b/lua/user/telescope.lua new file mode 100644 index 0000000..d27069b --- /dev/null +++ b/lua/user/telescope.lua @@ -0,0 +1,83 @@ +local status_ok, telescope = pcall(require, "telescope") +if not status_ok then + print "Error while loading telescope" + return +end + + +telescope.load_extension('media_files') + +local actions = require "telescope.actions" + +telescope.setup { + defaults = { + prompt_prefix = " ", + selection_caret = " ", + path_display = { "smart" }, + + mappings = { + i = { + ["<C-n>"] = actions.cycle_history_next, + ["<C-p>"] = actions.cycle_history_prev, + + ["<C-j>"] = actions.move_selection_next, + ["<C-k>"] = actions.move_selection_previous, + + ["<C-c>"] = actions.close, + + ["<Down>"] = actions.move_selection_next, + ["<Up>"] = actions.move_selection_previous, + + ["<CR>"] = actions.select_default, + ["<C-x>"] = actions.select_horizontal, + ["<C-v>"] = actions.select_vertical, + ["<C-t>"] = actions.select_tab, + + ["<C-u>"] = actions.preview_scrolling_up, + ["<C-d>"] = actions.preview_scrolling_down, + + ["<PageUp>"] = actions.results_scrolling_up, + ["<PageDown>"] = actions.results_scrolling_down, + + ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse, + ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better, + ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, + ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, + ["<C-l>"] = actions.complete_tag, + ["<C-_>"] = actions.which_key, -- keys from pressing <C-/> + }, + + n = { + ["<esc>"] = actions.close, + ["<CR>"] = actions.select_default, + ["<C-x>"] = actions.select_horizontal, + ["<C-v>"] = actions.select_vertical, + ["<C-t>"] = actions.select_tab, + + ["<Tab>"] = actions.toggle_selection + actions.move_selection_worse, + ["<S-Tab>"] = actions.toggle_selection + actions.move_selection_better, + ["<C-q>"] = actions.send_to_qflist + actions.open_qflist, + ["<M-q>"] = actions.send_selected_to_qflist + actions.open_qflist, + + ["j"] = actions.move_selection_next, + ["k"] = actions.move_selection_previous, + ["H"] = actions.move_to_top, + ["M"] = actions.move_to_middle, + ["L"] = actions.move_to_bottom, + + ["<Down>"] = actions.move_selection_next, + ["<Up>"] = actions.move_selection_previous, + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, + + ["<C-u>"] = actions.preview_scrolling_up, + ["<C-d>"] = actions.preview_scrolling_down, + + ["<PageUp>"] = actions.results_scrolling_up, + ["<PageDown>"] = actions.results_scrolling_down, + + ["?"] = actions.which_key, + }, + }, + }, +} diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua new file mode 100644 index 0000000..ede8999 --- /dev/null +++ b/lua/user/treesitter.lua @@ -0,0 +1,16 @@ +local status_ok, configs = pcall(require, "nvim-treesitter.configs") +if not status_ok then + return +end + +configs.setup { + ensure_installed = "maintained", + sync_install = false, + ignore_install = { "" }, + highlight = { + enable = true, + disable = { "" }, + additional_vim_regex_highlighting = true, + }, + indent = { enable = true, disable = { "yaml" } }, +} diff --git a/lua/user/vimplug.lua b/lua/user/vimplug.lua new file mode 100644 index 0000000..f182a4b --- /dev/null +++ b/lua/user/vimplug.lua @@ -0,0 +1,65 @@ +local configs = { + lazy = {}, + start = {} +} + +local Plug = { + begin = vim.fn['plug#begin'], + + -- "end" is a keyword, need something else + ends = function() + vim.fn['plug#end']() + + for i, config in pairs(configs.start) do + config() + end + end +} + +-- Not a fan of global functions, but it'll work better +-- for the people that will copy/paste this +_G.VimPlugApplyConfig = function(plugin_name) + local fn = configs.lazy[plugin_name] + if type(fn) == 'function' then fn() end +end + +local plug_name = function(repo) + return repo:match("^[%w-]+/([%w-_.]+)$") +end + +-- "Meta-functions" +local meta = { + + -- Function call "operation" + __call = function(self, repo, opts) + opts = opts or vim.empty_dict() + + -- we declare some aliases for `do` and `for` + opts['do'] = opts.run + opts.run = nil + + opts['for'] = opts.ft + opts.ft = nil + + vim.call('plug#', repo, opts) + + -- Add basic support to colocate plugin config + if type(opts.config) == 'function' then + local plugin = opts.as or plug_name(repo) + + if opts['for'] == nil and opts.on == nil then + configs.start[plugin] = opts.config + else + configs.lazy[plugin] = opts.config + + local user_cmd = [[ autocmd! User %s ++once lua VimPlugApplyConfig('%s') ]] + vim.cmd(user_cmd:format(plugin, plugin)) + end + + end + end +} + +-- Meta-tables are awesome +return setmetatable(Plug, meta) + |