From eabb9593bf5ca524f7aac9e2172a23dc1aa39ea8 Mon Sep 17 00:00:00 2001 From: histalek Date: Wed, 7 Dec 2022 08:31:17 +0100 Subject: [PATCH] nvim: Completely rewrite nvim plugin configs --- .config/nvim/.stylua.toml | 2 + .config/nvim/init.lua | 48 ++++---- .config/nvim/lua/core/keymaps.lua | 23 ++++ .config/nvim/lua/core/options.lua | 46 ++++++++ .config/nvim/lua/keymap.lua | 8 -- .config/nvim/lua/plugin-setup.lua | 106 ++++++++++++++++++ .config/nvim/lua/plugins.lua | 115 -------------------- .config/nvim/lua/plugins/autopairs.lua | 23 ++++ .config/nvim/lua/plugins/comment.lua | 6 + .config/nvim/lua/plugins/gitsigns.lua | 6 + .config/nvim/lua/plugins/leap.lua | 6 + .config/nvim/lua/plugins/lsp/lspconfig.lua | 94 ++++++++++++++++ .config/nvim/lua/plugins/lsp/lspsaga.lua | 14 +++ .config/nvim/lua/plugins/lsp/mason.lua | 37 +++++++ .config/nvim/lua/plugins/lsp/null-ls.lua | 38 +++++++ .config/nvim/lua/plugins/lualine.lua | 11 ++ .config/nvim/lua/plugins/nvim-autopairs.lua | 25 +++++ .config/nvim/lua/plugins/nvim-cmp.lua | 45 ++++++++ .config/nvim/lua/plugins/nvim-tree.lua | 10 ++ .config/nvim/lua/plugins/telescope.lua | 21 ++++ .config/nvim/lua/plugins/toggleterm.lua | 24 ++++ .config/nvim/lua/plugins/treesitter.lua | 29 +++++ .config/nvim/lua/plugins/which-key.lua | 11 ++ 23 files changed, 600 insertions(+), 148 deletions(-) create mode 100644 .config/nvim/.stylua.toml create mode 100644 .config/nvim/lua/core/keymaps.lua create mode 100644 .config/nvim/lua/core/options.lua delete mode 100644 .config/nvim/lua/keymap.lua create mode 100644 .config/nvim/lua/plugin-setup.lua delete mode 100644 .config/nvim/lua/plugins.lua create mode 100644 .config/nvim/lua/plugins/autopairs.lua create mode 100644 .config/nvim/lua/plugins/comment.lua create mode 100644 .config/nvim/lua/plugins/gitsigns.lua create mode 100644 .config/nvim/lua/plugins/leap.lua create mode 100644 .config/nvim/lua/plugins/lsp/lspconfig.lua create mode 100644 .config/nvim/lua/plugins/lsp/lspsaga.lua create mode 100644 .config/nvim/lua/plugins/lsp/mason.lua create mode 100644 .config/nvim/lua/plugins/lsp/null-ls.lua create mode 100644 .config/nvim/lua/plugins/lualine.lua create mode 100644 .config/nvim/lua/plugins/nvim-autopairs.lua create mode 100644 .config/nvim/lua/plugins/nvim-cmp.lua create mode 100644 .config/nvim/lua/plugins/nvim-tree.lua create mode 100644 .config/nvim/lua/plugins/telescope.lua create mode 100644 .config/nvim/lua/plugins/toggleterm.lua create mode 100644 .config/nvim/lua/plugins/treesitter.lua create mode 100644 .config/nvim/lua/plugins/which-key.lua diff --git a/.config/nvim/.stylua.toml b/.config/nvim/.stylua.toml new file mode 100644 index 0000000..0435f67 --- /dev/null +++ b/.config/nvim/.stylua.toml @@ -0,0 +1,2 @@ +indent_type = "Spaces" +indent_width = 2 diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 306c568..7253aa6 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,28 +1,26 @@ --- Basic vim options -vim.opt.clipboard = 'unnamedplus' -- System clipboard -vim.opt.cursorcolumn = true -vim.opt.cursorline = true -vim.opt.expandtab = true -vim.opt.hidden = true -vim.opt.history = 30 -vim.opt.ignorecase = true -vim.opt.list = true -vim.opt.listchars = 'trail:•,tab:🡺 ,' -vim.opt.number = true -vim.opt.relativenumber = false -vim.opt.shiftwidth = 2 -vim.opt.showmode = true -vim.opt.smartcase = true -vim.opt.swapfile = false -vim.opt.tabstop = 2 -vim.opt.termguicolors = true -vim.opt.timeoutlen = 200 -vim.opt.wrap = true +-- Load configuration from different lua files --- Switch to as global mapleader and load keymapping config -vim.g.mapleader = ' ' -require('keymap') +--- Basic options +require("core.options") --- Require lua/plugins.lua config -require('plugins') +-- Keymap config +require("core.keymaps") +-- Plugin configs, setup has to come first +require("plugin-setup") +require("plugins.comment") +require("plugins.nvim-autopairs") +require("plugins.nvim-tree") +require("plugins.gitsigns") +require("plugins.treesitter") +require("plugins.lualine") +require("plugins.toggleterm") +require("plugins.autopairs") +require("plugins.which-key") +require("plugins.telescope") +require("plugins.nvim-cmp") +require("plugins.lsp.mason") +require("plugins.lsp.lspsaga") +require("plugins.lsp.lspconfig") +require("plugins.lsp.null-ls") +require("plugins.leap") diff --git a/.config/nvim/lua/core/keymaps.lua b/.config/nvim/lua/core/keymaps.lua new file mode 100644 index 0000000..1fa4708 --- /dev/null +++ b/.config/nvim/lua/core/keymaps.lua @@ -0,0 +1,23 @@ +-- Convenience function. description parameter is used by `whichkey` +local function map(mode, keybind, command, description) + vim.api.nvim_set_keymap(mode, keybind, command, { desc = description, silent = true, noremap = true }) +end + +-- Switch to as global mapleader +vim.g.mapleader = " " + +-- Don't place single deleted characters in a buffer +map("n", "x", '"_x') + +-- Increment and decrement numbers +map("n", "+", "", "Increment number under cursor") +map("n", "-", "", "Decrement number under cursor") + +-- File explorer +map("n", "e", ":NvimTreeToggle", "Toggle file explorer") + +-- telescope +map("n", "ff", "Telescope find_files", "Find files within cwd") -- respects .gitignore +map("n", "fs", "Telescope live_grep", "Find string in cwd") +map("n", "fb", "Telescope buffers", "List open buffers in current neovim instance") +map("n", "fh", "Telescope help_tags", "List available help tags") diff --git a/.config/nvim/lua/core/options.lua b/.config/nvim/lua/core/options.lua new file mode 100644 index 0000000..0ec58af --- /dev/null +++ b/.config/nvim/lua/core/options.lua @@ -0,0 +1,46 @@ +local opt = vim.opt + +-- clipboard +opt.clipboard = "unnamedplus" -- System clipboard + +-- cursor +opt.cursorcolumn = true +opt.cursorline = true + +-- linenumbers +opt.number = true +opt.relativenumber = false + +-- tabs / indentation +opt.autoindent = true +opt.expandtab = true +opt.shiftwidth = 2 +opt.tabstop = 2 +opt.wrap = true + +-- undo / buffers +opt.swapfile = false +opt.undofile = true + +-- search +opt.ignorecase = true +opt.smartcase = true + +-- appearance +opt.list = true +opt.listchars = "trail:•,tab:⭾ ," +opt.showmode = true +opt.signcolumn = "yes" +opt.termguicolors = true + +-- split windows +opt.splitright = true +opt.splitbelow = true + +-- timeout (e.g. after which time 'which-key' shows up) +opt.timeoutlen = 400 + +-- other +opt.hidden = true +opt.history = 30 +opt.backspace = "indent,eol,start" diff --git a/.config/nvim/lua/keymap.lua b/.config/nvim/lua/keymap.lua deleted file mode 100644 index 145a641..0000000 --- a/.config/nvim/lua/keymap.lua +++ /dev/null @@ -1,8 +0,0 @@ --- Convenience function. description parameter is used by `whichkey` -local function map(mode, keybind, command, description) - vim.api.nvim_set_keymap(mode, keybind, command, { desc = description, silent = true, noremap = true }) -end - -map('n', 'fr', ':History', 'Show recently used files') -map('n', 'ff', ':e %:h/', 'Show files in directory') - diff --git a/.config/nvim/lua/plugin-setup.lua b/.config/nvim/lua/plugin-setup.lua new file mode 100644 index 0000000..88f20e1 --- /dev/null +++ b/.config/nvim/lua/plugin-setup.lua @@ -0,0 +1,106 @@ +-- Autocommand to reload neovim plugins when this file gets saved +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugin-setup.lua source | PackerCompile + augroup end +]]) + +-- Guard if packer can't be found +local status, packer = pcall(require, "packer") +if not status then + return +end + +return packer.startup({ + function(use) + use("wbthomason/packer.nvim") + + -- Lua functions used by many plugins + use("nvim-lua/plenary.nvim") + + -- Theming - one for all package. autocomplete :colorscheme to see what is available + use("RRethy/nvim-base16") + vim.cmd([[colorscheme base16-espresso]]) + + -- Completion and linting + use("williamboman/mason.nvim") + use("williamboman/mason-lspconfig.nvim") + + -- Configuring lsp servers + use("neovim/nvim-lspconfig") + use("hrsh7th/cmp-nvim-lsp") + use({ "glepnir/lspsaga.nvim", branch = "main" }) + use("jose-elias-alvarez/typescript.nvim") + use("onsails/lspkind.nvim") + + use("jose-elias-alvarez/null-ls.nvim") + use("jayp0521/mason-null-ls.nvim") + + -- Autopairs + use("windwp/nvim-autopairs") + + -- git + use("lewis6991/gitsigns.nvim") + + use("tpope/vim-surround") + + -- Highlight colors + use({ + "norcalli/nvim-colorizer.lua", + ft = { "css", "javascript", "vim", "html" }, + config = [[require('colorizer').setup {'css', 'javascript', 'vim', 'html'}]], + }) + + -- Syntax highlighting + use({ + "nvim-treesitter/nvim-treesitter", + run = function() + local ts_update = require("nvim-treesitter.install").update({ with_sync = true }) + ts_update() + end, + }) + + -- Lualine statusline + use("nvim-lualine/lualine.nvim") + + -- fuzzy finding with telescope + use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" }) + use({ "nvim-telescope/telescope.nvim", branch = "0.1.x" }) + + -- autocompletion + use("hrsh7th/nvim-cmp") + use("hrsh7th/cmp-buffer") + use("hrsh7th/cmp-path") + + -- snippets + use("L3MON4D3/LuaSnip") + use("saadparwaiz1/cmp_luasnip") + use("rafamadriz/friendly-snippets") + + -- toggleterm + use({ "akinsho/toggleterm.nvim", tag = "v2.*" }) + + -- easier commenting + use("numToStr/Comment.nvim") + + -- File explorer + use("nvim-tree/nvim-tree.lua") + use("nvim-tree/nvim-web-devicons") + + -- Popup for available keybinds + use("folke/which-key.nvim") + + -- Fast onscreen navigation + use("ggandor/leap.nvim") + + if packer.bootstrap then + require("packer").sync() + end + end, + config = { + display = { + open_fn = require("packer.util").float, + }, + }, +}) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua deleted file mode 100644 index 0c1ea28..0000000 --- a/.config/nvim/lua/plugins.lua +++ /dev/null @@ -1,115 +0,0 @@ --- Automatically run :PackerCompile whenever plugins.lua is updated -vim.api.nvim_create_autocmd('BufWritePost', { - group = vim.api.nvim_create_augroup('PACKER', { clear = true }), - pattern = 'plugins.lua', - command = 'source | PackerCompile', -}) - -vim.cmd [[packadd packer.nvim]] - -return require('packer').startup({function(use) - use 'wbthomason/packer.nvim' - - -- Theming - one for all package. autocomplete :colorscheme to see what is available - use 'RRethy/nvim-base16' - vim.cmd [[colorscheme base16-espresso]] - - -- Pretty symbols - use 'kyazdani42/nvim-web-devicons' - - -- Completion and linting - use 'neovim/nvim-lspconfig' - - -- Autopairs - use 'windwp/nvim-autopairs' - require("nvim-autopairs").setup() - - -- Highlight colors - use { - 'norcalli/nvim-colorizer.lua', - ft = { 'css', 'javascript', 'vim', 'html' }, - config = [[require('colorizer').setup {'css', 'javascript', 'vim', 'html'}]], - } - - -- Syntax highlighting - use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' } - require'nvim-treesitter.configs'.setup { - ensure_installed = { - "bash", - "c", - "css", - "dockerfile", - "go", - "html", - "javascript", - "json", - "latex", - "lua", - "make", - "python", - "rust", - "vue", - "yaml", - }, - sync_install = false, - auto_install = true, -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally - highlight = { - enable = true, - -- disable = { "c", "rust" }, - }, - } - - -- Lualine statusline - use 'nvim-lualine/lualine.nvim' - require('lualine').setup { - options = { - icon_enabled = true, - theme = 'auto', - } - } - - -- fzf - use 'junegunn/fzf' - use 'junegunn/fzf.vim' - - -- toggleterm - use { "akinsho/toggleterm.nvim", tag = 'v2.*' } - require("toggleterm").setup{ - open_mapping = [[]], - hide_numbers = true, - persist_size = true, - persist_mode = true, - direction = 'horizontal', -- 'float', - close_on_exit = true, - shell = vim.o.shell, - auto_scroll = true, - float_opts = { - border = 'curved', - }, - winbar = { - enabled = false, - name_formatter = function(term) - return term.name - end - }, - } - - -- Popup for available keybinds - use { - "folke/which-key.nvim", - config = function() - require("which-key").setup{ - window = { - border = "double", - position = "bottom", - }, - } - end -} - -end, -config = { - display = { - open_fn = require('packer.util').float, - } -}}) diff --git a/.config/nvim/lua/plugins/autopairs.lua b/.config/nvim/lua/plugins/autopairs.lua new file mode 100644 index 0000000..ff3577b --- /dev/null +++ b/.config/nvim/lua/plugins/autopairs.lua @@ -0,0 +1,23 @@ +local status, autopairs = pcall(require, "nvim-autopairs") +if not status then + return +end + +autopairs.setup({ + check_ts = true, + ts_config = { + lua = { "string" }, + }, +}) + +local cmp_autopairs_setup, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp") +if not cmp_autopairs_setup then + return +end + +local cmp_setup, cmp = pcall(require, "cmp") +if not cmp_setup then + return +end + +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) diff --git a/.config/nvim/lua/plugins/comment.lua b/.config/nvim/lua/plugins/comment.lua new file mode 100644 index 0000000..36dca19 --- /dev/null +++ b/.config/nvim/lua/plugins/comment.lua @@ -0,0 +1,6 @@ +local status, comment = pcall(require, "Comment") +if not status then + return +end + +comment.setup() diff --git a/.config/nvim/lua/plugins/gitsigns.lua b/.config/nvim/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..59bebcf --- /dev/null +++ b/.config/nvim/lua/plugins/gitsigns.lua @@ -0,0 +1,6 @@ +local status, gitsigns = pcall(require, "gitsigns") +if not status then + return +end + +gitsigns.setup() diff --git a/.config/nvim/lua/plugins/leap.lua b/.config/nvim/lua/plugins/leap.lua new file mode 100644 index 0000000..aa93a9c --- /dev/null +++ b/.config/nvim/lua/plugins/leap.lua @@ -0,0 +1,6 @@ +local status, leap = pcall(require, "leap") +if not status then + return +end + +leap.add_default_mappings() diff --git a/.config/nvim/lua/plugins/lsp/lspconfig.lua b/.config/nvim/lua/plugins/lsp/lspconfig.lua new file mode 100644 index 0000000..2e17160 --- /dev/null +++ b/.config/nvim/lua/plugins/lsp/lspconfig.lua @@ -0,0 +1,94 @@ +local status_lspconfig, lspconfig = pcall(require, "lspconfig") +if not status_lspconfig then + return +end + +local status_cmp_nvim_lsp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not status_cmp_nvim_lsp then + return +end + +local status_typescript, typescript = pcall(require, "typescript") +if not status_typescript then + return +end + +local keymap = vim.keymap + +-- enable keybinds only for when lsp server available +local on_attach = function(client, bufnr) + local opts = { noremap = true, silent = true, buffer = bufnr } + + keymap.set("n", "gf", "Lspsaga lsp_finder", opts) -- show definition, references + keymap.set("n", "gD", "lua vim.lsp.buf.declaration()", opts) -- got to declaration + keymap.set("n", "gd", "Lspsaga peek_definition", opts) -- see definition and make edits in window + keymap.set("n", "gi", "lua vim.lsp.buf.implementation()", opts) -- go to implementation + keymap.set("n", "ca", "Lspsaga code_action", opts) -- see available code actions + keymap.set("n", "rn", "Lspsaga rename", opts) -- smart rename + keymap.set("n", "D", "Lspsaga show_line_diagnostics", opts) -- show diagnostics for line + keymap.set("n", "d", "Lspsaga show_cursor_diagnostics", opts) -- show diagnostics for cursor + keymap.set("n", "[d", "Lspsaga diagnostic_jump_prev", opts) -- jump to previous diagnostic in buffer + keymap.set("n", "]d", "Lspsaga diagnostic_jump_next", opts) -- jump to next diagnostic in buffer + keymap.set("n", "K", "Lspsaga hover_doc", opts) -- show documentation for what is under cursor + keymap.set("n", "o", "LSoutlineToggle", opts) -- see outline on right hand side + + if client.name == "tsserver" then + keymap.set("n", "rf", ":TypescriptRenameFile") -- rename file and update imports + keymap.set("n", "oi", ":TypescriptOrganizeImports") -- organize imports (not in youtube nvim video) + keymap.set("n", "ru", ":TypescriptRemoveUnused") -- remove unused variables (not in youtube nvim video) + end +end + +local capabilities = cmp_nvim_lsp.default_capabilities() + +local signs = { Error = " ", Warn = " ", Hint = "ﴞ ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end + +lspconfig["html"].setup({ + capabilities = capabilities, + on_attach = on_attach, +}) + +typescript.setup({ + server = { + capabilities = capabilities, + on_attach = on_attach, + }, +}) + +lspconfig["cssls"].setup({ + capabilities = capabilities, + on_attach = on_attach, +}) + +lspconfig["tailwindcss"].setup({ + capabilities = capabilities, + on_attach = on_attach, +}) + +lspconfig["emmet_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, +}) + +lspconfig["sumneko_lua"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { + Lua = { + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, +}) diff --git a/.config/nvim/lua/plugins/lsp/lspsaga.lua b/.config/nvim/lua/plugins/lsp/lspsaga.lua new file mode 100644 index 0000000..873ef94 --- /dev/null +++ b/.config/nvim/lua/plugins/lsp/lspsaga.lua @@ -0,0 +1,14 @@ +local status_saga, saga = pcall(require, "lspsaga") +if not status_saga then + return +end + +saga.init_lsp_saga({ + move_in_saga = { prev = "", next = "" }, + finder_action_keys = { + open = "", + }, + definition_action_keys = { + edit = "", + }, +}) diff --git a/.config/nvim/lua/plugins/lsp/mason.lua b/.config/nvim/lua/plugins/lsp/mason.lua new file mode 100644 index 0000000..e59fd19 --- /dev/null +++ b/.config/nvim/lua/plugins/lsp/mason.lua @@ -0,0 +1,37 @@ +local status_mason, mason = pcall(require, "mason") +if not status_mason then + return +end + +local status_lspconfig, mason_lspconfig = pcall(require, "mason-lspconfig") +if not status_lspconfig then + return +end + +local status_null_ls, mason_null_ls = pcall(require, "mason-null-ls") +if not status_null_ls then + return +end + +mason.setup() + +mason_lspconfig.setup({ + ensure_installed = { + "tsserver", + "html", + "cssls", + "tailwindcss", + "sumneko_lua", + "emmet_ls", + }, + automatic_installation = true, +}) + +mason_null_ls.setup({ + ensure_installed = { + "prettier", + "stylua", + "eslint_d", + }, + automatic_installation = true, +}) diff --git a/.config/nvim/lua/plugins/lsp/null-ls.lua b/.config/nvim/lua/plugins/lsp/null-ls.lua new file mode 100644 index 0000000..9019d1d --- /dev/null +++ b/.config/nvim/lua/plugins/lsp/null-ls.lua @@ -0,0 +1,38 @@ +local status, null_ls = pcall(require, "null-ls") +if not status then + return +end + +local formatting = null_ls.builtins.formatting +local diagnostics = null_ls.builtins.diagnostics + +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +null_ls.setup({ + sources = { + formatting.prettier, + formatting.stylua, + diagnostics.eslint_d.with({ + condition = function(utils) + return utils.root_has_file(".eslintrc.js") + end, + }), + }, + on_attach = function(current_client, bufnr) + if current_client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ + filter = function(client) + return client.name == "null-ls" + end, + bufnr = bufnr, + }) + end, + }) + end + end, +}) diff --git a/.config/nvim/lua/plugins/lualine.lua b/.config/nvim/lua/plugins/lualine.lua new file mode 100644 index 0000000..7524d8e --- /dev/null +++ b/.config/nvim/lua/plugins/lualine.lua @@ -0,0 +1,11 @@ +local status, lualine = pcall(require, "lualine") +if not status then + return +end + +lualine.setup({ + options = { + icon_enabled = true, + theme = "auto", + }, +}) diff --git a/.config/nvim/lua/plugins/nvim-autopairs.lua b/.config/nvim/lua/plugins/nvim-autopairs.lua new file mode 100644 index 0000000..225b5fe --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-autopairs.lua @@ -0,0 +1,25 @@ +local status, autopairs = pcall(require, "nvim-autopairs") +if not status then + return +end + +autopairs.setup({ + check_ts = true, + ts_config = { + lua = { "string" }, + javascript = { "template_string" }, + java = false, + }, +}) + +local cmp_autopairs_status, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp") +if not cmp_autopairs_status then + return +end + +local cmp_status, cmp = pcall(require, "cmp") +if not cmp_status then + return +end + +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) diff --git a/.config/nvim/lua/plugins/nvim-cmp.lua b/.config/nvim/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..922c8bf --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-cmp.lua @@ -0,0 +1,45 @@ +local status_cmp, cmp = pcall(require, "cmp") +if not status_cmp then + return +end + +local status_luasnip, luasnip = pcall(require, "luasnip") +if not status_luasnip then + return +end + +local status_lspkind, lspkind = pcall(require, "lspkind") +if not status_lspkind then + return +end + +require("luasnip/loaders/from_vscode").lazy_load() + +vim.opt.completeopt = "menu,menuone,noselect" + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = false }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }), + formatting = { + format = lspkind.cmp_format({ + maxwidth = 50, + ellipsis_char = "...", + }), + }, +}) diff --git a/.config/nvim/lua/plugins/nvim-tree.lua b/.config/nvim/lua/plugins/nvim-tree.lua new file mode 100644 index 0000000..f817ab4 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-tree.lua @@ -0,0 +1,10 @@ +local status, nvimtree = pcall(require, "nvim-tree") +if not status then + return +end + +-- recommended settings by nvim-tree documentation +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +nvimtree.setup() diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..17fbaf9 --- /dev/null +++ b/.config/nvim/lua/plugins/telescope.lua @@ -0,0 +1,21 @@ +local status_telescope, telescope = pcall(require, "telescope") +if not status_telescope then + return +end + +local status_actions, actions = pcall(require, "telescope.actions") +if not status_actions then + return +end + +telescope.setup({ + defaults = { + mappings = { + i = { + [""] = actions.move_selection_previous, + [""] = actions.move_selection_next, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + }, + }, + }, +}) diff --git a/.config/nvim/lua/plugins/toggleterm.lua b/.config/nvim/lua/plugins/toggleterm.lua new file mode 100644 index 0000000..f1265ab --- /dev/null +++ b/.config/nvim/lua/plugins/toggleterm.lua @@ -0,0 +1,24 @@ +local status, toggleterm = pcall(require, "toggleterm") +if not status then + return +end + +toggleterm.setup({ + open_mapping = [[]], + hide_numbers = true, + persist_size = true, + persist_mode = true, + direction = "float", + close_on_exit = true, + shell = vim.o.shell, + auto_scroll = true, + float_opts = { + border = "curved", + }, + winbar = { + enabled = false, + name_formatter = function(term) + return term.name + end, + }, +}) diff --git a/.config/nvim/lua/plugins/treesitter.lua b/.config/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..944f413 --- /dev/null +++ b/.config/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,29 @@ +local status, treesitter = pcall(require, "nvim-treesitter.configs") +if not status then + return +end + +treesitter.setup({ + ensure_installed = { + "bash", + "c", + "css", + "dockerfile", + "go", + "html", + "javascript", + "json", + "latex", + "lua", + "make", + "python", + "rust", + "vue", + "yaml", + }, + sync_install = false, + auto_install = true, -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + highlight = { enable = true }, + indent = { enable = true }, + autotag = { enabled = true }, +}) diff --git a/.config/nvim/lua/plugins/which-key.lua b/.config/nvim/lua/plugins/which-key.lua new file mode 100644 index 0000000..5aa42d3 --- /dev/null +++ b/.config/nvim/lua/plugins/which-key.lua @@ -0,0 +1,11 @@ +local status, whichkey = pcall(require, "which-key") +if not status then + return +end + +whichkey.setup({ + window = { + border = "double", + position = "bottom", + }, +})