From adefa5ce2acb5972b9733117e3146baeeffdd099 Mon Sep 17 00:00:00 2001 From: Nikurasu Date: Fri, 23 Dec 2022 12:57:25 +0100 Subject: [PATCH] Rewrite Nvim Config based on kickstart.nvim --- nvim/init.lua | 123 ++++++++++++++++-- nvim/lua/keybindings/init.lua | 6 - nvim/lua/plugins/cmp.lua | 41 ++++++ nvim/lua/plugins/cmp/init.lua | 8 -- nvim/lua/plugins/comment.lua | 1 + nvim/lua/plugins/dashboard/init.lua | 1 - .../plugins/{fidget/init.lua => fidget.lua} | 0 nvim/lua/plugins/gitsigns.lua | 9 ++ nvim/lua/plugins/indent_blankline.lua | 4 + nvim/lua/plugins/init.lua | 9 ++ nvim/lua/plugins/lualine.lua | 8 ++ nvim/lua/plugins/lualine/init.lua | 7 - .../{mason/lspconfig/init.lua => mason.lua} | 15 ++- nvim/lua/plugins/mason/init.lua | 1 - nvim/lua/plugins/nvim-tree/init.lua | 8 -- nvim/lua/plugins/packer.lua | 61 +++++++++ nvim/lua/plugins/packer/init.lua | 62 --------- nvim/lua/plugins/transparent/init.lua | 3 - nvim/lua/plugins/treesitter.lua | 65 +++++++++ nvim/lua/plugins/treesitter/init.lua | 12 -- 20 files changed, 320 insertions(+), 124 deletions(-) delete mode 100644 nvim/lua/keybindings/init.lua create mode 100644 nvim/lua/plugins/cmp.lua delete mode 100644 nvim/lua/plugins/cmp/init.lua create mode 100644 nvim/lua/plugins/comment.lua delete mode 100644 nvim/lua/plugins/dashboard/init.lua rename nvim/lua/plugins/{fidget/init.lua => fidget.lua} (100%) create mode 100644 nvim/lua/plugins/gitsigns.lua create mode 100644 nvim/lua/plugins/indent_blankline.lua create mode 100644 nvim/lua/plugins/init.lua create mode 100644 nvim/lua/plugins/lualine.lua delete mode 100644 nvim/lua/plugins/lualine/init.lua rename nvim/lua/plugins/{mason/lspconfig/init.lua => mason.lua} (64%) delete mode 100644 nvim/lua/plugins/mason/init.lua delete mode 100644 nvim/lua/plugins/nvim-tree/init.lua create mode 100644 nvim/lua/plugins/packer.lua delete mode 100644 nvim/lua/plugins/packer/init.lua delete mode 100644 nvim/lua/plugins/transparent/init.lua create mode 100644 nvim/lua/plugins/treesitter.lua delete mode 100644 nvim/lua/plugins/treesitter/init.lua diff --git a/nvim/init.lua b/nvim/init.lua index ca99d5c..744048f 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,4 +1,4 @@ --- Bootstrap +-- Install packer local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim' local is_bootstrap = false if vim.fn.empty(vim.fn.glob(install_path)) > 0 then @@ -7,8 +7,6 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.cmd [[packadd packer.nvim]] end -require('plugins.packer') - -- When we are bootstrapping a configuration, it doesn't -- make sense to execute the rest of the init.lua. -- @@ -22,14 +20,115 @@ if is_bootstrap then return end --- General Configuration -vim.opt.number = true -vim.opt.relativenumber = true -vim.opt.ignorecase = true -vim.opt.tabstop = 2 -vim.opt.shiftwidth = 2 -vim.opt.expandtab = true +-- Automatically source and re-compile packer whenever you save this init.lua +local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true }) +vim.api.nvim_create_autocmd('BufWritePost', { + command = 'source | PackerCompile', + group = packer_group, + pattern = vim.fn.expand '$MYVIMRC', +}) -vim.cmd('colorscheme base16-tomorrow-night-eighties') +-- [[ Setting options ]] +-- See `:help vim.o` -require('keybindings') \ No newline at end of file +-- Set highlight on search +vim.o.hlsearch = false + +-- Make line numbers default +vim.wo.number = true + +-- Enable mouse mode +vim.o.mouse = 'a' + +-- Enable break indent +vim.o.breakindent = true + +-- Save undo history +vim.o.undofile = true + +-- Case insensitive searching UNLESS /C or capital in search +vim.o.ignorecase = true +vim.o.smartcase = true + +-- Decrease update time +vim.o.updatetime = 250 +vim.wo.signcolumn = 'yes' + +-- Set colorscheme +vim.o.termguicolors = true +vim.cmd [[colorscheme base16-tomorrow-night-eighties]] + +-- Set completeopt to have a better completion experience +vim.o.completeopt = 'menuone,noselect' + +-- [[ Basic Keymaps ]] +-- Set as the leader key +-- See `:help mapleader` +-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +-- Keymaps for better default experience +-- See `:help vim.keymap.set()` +vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) + +-- Remap for 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 }) + +-- Diagnostic keymaps +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next) +vim.keymap.set('n', 'e', vim.diagnostic.open_float) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + +require('plugins') + +-- LSP settings. +-- This function gets run when an LSP connects to a particular buffer. +local on_attach = function(_, bufnr) + -- NOTE: Remember that lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself + -- many times. + -- + -- In this case, we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + local nmap = function(keys, func, desc) + if desc then + desc = 'LSP: ' .. desc + end + + vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) + end + + nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') + nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + + nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') + nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') + nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') + + -- See `:help K` for why this keymap + nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + + -- Lesser used LSP functionality + nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') + nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') + nmap('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, '[W]orkspace [L]ist Folders') + + -- Create a command `:Format` local to the LSP buffer + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) + vim.lsp.buf.format() + end, { desc = 'Format current buffer with LSP' }) +end + +-- Setup neovim lua configuration +-- require('neodev').setup() +-- +-- nvim-cmp supports additional completion capabilities, so broadcast that to servers +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) diff --git a/nvim/lua/keybindings/init.lua b/nvim/lua/keybindings/init.lua deleted file mode 100644 index 6effb0f..0000000 --- a/nvim/lua/keybindings/init.lua +++ /dev/null @@ -1,6 +0,0 @@ -vim.g.mapleader = ' ' - -vim.keymap.set('', 'ft', ':NvimTreeToggle') -vim.keymap.set('', 'ff', ':NvimTreeFocus') - -vim.keymap.set('n', 'bl', ':buffers') \ No newline at end of file diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua new file mode 100644 index 0000000..732a6c1 --- /dev/null +++ b/nvim/lua/plugins/cmp.lua @@ -0,0 +1,41 @@ +local cmp = require 'cmp' +local luasnip = require 'luasnip' + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = 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() + 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' }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} \ No newline at end of file diff --git a/nvim/lua/plugins/cmp/init.lua b/nvim/lua/plugins/cmp/init.lua deleted file mode 100644 index a116819..0000000 --- a/nvim/lua/plugins/cmp/init.lua +++ /dev/null @@ -1,8 +0,0 @@ -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - -require('cmp').setup({ - sources = { - { name = 'nvim_lsp' }, - } -}) \ No newline at end of file diff --git a/nvim/lua/plugins/comment.lua b/nvim/lua/plugins/comment.lua new file mode 100644 index 0000000..d2af0f2 --- /dev/null +++ b/nvim/lua/plugins/comment.lua @@ -0,0 +1 @@ +require('Comment').setup() \ No newline at end of file diff --git a/nvim/lua/plugins/dashboard/init.lua b/nvim/lua/plugins/dashboard/init.lua deleted file mode 100644 index 5b5cc43..0000000 --- a/nvim/lua/plugins/dashboard/init.lua +++ /dev/null @@ -1 +0,0 @@ -local db = require('dashboard') \ No newline at end of file diff --git a/nvim/lua/plugins/fidget/init.lua b/nvim/lua/plugins/fidget.lua similarity index 100% rename from nvim/lua/plugins/fidget/init.lua rename to nvim/lua/plugins/fidget.lua diff --git a/nvim/lua/plugins/gitsigns.lua b/nvim/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..356c415 --- /dev/null +++ b/nvim/lua/plugins/gitsigns.lua @@ -0,0 +1,9 @@ +require('gitsigns').setup { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + } \ No newline at end of file diff --git a/nvim/lua/plugins/indent_blankline.lua b/nvim/lua/plugins/indent_blankline.lua new file mode 100644 index 0000000..8cd798d --- /dev/null +++ b/nvim/lua/plugins/indent_blankline.lua @@ -0,0 +1,4 @@ +require('indent_blankline').setup { + char = '┊', + show_trailing_blankline_indent = false, + } \ No newline at end of file diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua new file mode 100644 index 0000000..523ca64 --- /dev/null +++ b/nvim/lua/plugins/init.lua @@ -0,0 +1,9 @@ +require('plugins.packer') +require('plugins.lualine') +require('plugins.comment') +require('plugins.indent_blankline') +require('plugins.gitsigns') +require('plugins.treesitter') +require('plugins.mason') +require('plugins.fidget') +require('plugins.cmp') \ No newline at end of file diff --git a/nvim/lua/plugins/lualine.lua b/nvim/lua/plugins/lualine.lua new file mode 100644 index 0000000..cc7036f --- /dev/null +++ b/nvim/lua/plugins/lualine.lua @@ -0,0 +1,8 @@ +require('lualine').setup { + options = { + icons_enabled = false, + theme = 'base16', + component_separators = '|', + section_separators = '', + }, + } \ No newline at end of file diff --git a/nvim/lua/plugins/lualine/init.lua b/nvim/lua/plugins/lualine/init.lua deleted file mode 100644 index 5ce48b8..0000000 --- a/nvim/lua/plugins/lualine/init.lua +++ /dev/null @@ -1,7 +0,0 @@ -require('lualine').setup({ - options = { - theme = 'base16', - section_separators = { left = '', right = '' } - }, - extensions = {'nvim-tree'} - }) \ No newline at end of file diff --git a/nvim/lua/plugins/mason/lspconfig/init.lua b/nvim/lua/plugins/mason.lua similarity index 64% rename from nvim/lua/plugins/mason/lspconfig/init.lua rename to nvim/lua/plugins/mason.lua index f75c65e..c4e87f0 100644 --- a/nvim/lua/plugins/mason/lspconfig/init.lua +++ b/nvim/lua/plugins/mason.lua @@ -1,12 +1,19 @@ -local mason_lspconfig = require 'mason-lspconfig' - -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) +require('mason').setup() local servers = { tsserver = {}, + + sumneko_lua = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + }, } +-- Ensure the servers above are installed +local mason_lspconfig = require 'mason-lspconfig' + mason_lspconfig.setup { ensure_installed = vim.tbl_keys(servers), } diff --git a/nvim/lua/plugins/mason/init.lua b/nvim/lua/plugins/mason/init.lua deleted file mode 100644 index 03646c3..0000000 --- a/nvim/lua/plugins/mason/init.lua +++ /dev/null @@ -1 +0,0 @@ -require("mason").setup() \ No newline at end of file diff --git a/nvim/lua/plugins/nvim-tree/init.lua b/nvim/lua/plugins/nvim-tree/init.lua deleted file mode 100644 index db5c1d9..0000000 --- a/nvim/lua/plugins/nvim-tree/init.lua +++ /dev/null @@ -1,8 +0,0 @@ -require("nvim-tree").setup({ - open_on_setup = false, - actions = { - open_file = { - quit_on_open = true, - } - } - }) \ No newline at end of file diff --git a/nvim/lua/plugins/packer.lua b/nvim/lua/plugins/packer.lua new file mode 100644 index 0000000..d582655 --- /dev/null +++ b/nvim/lua/plugins/packer.lua @@ -0,0 +1,61 @@ +require('packer').startup(function(use) + -- Package manager + use 'wbthomason/packer.nvim' + + use { -- LSP Configuration & Plugins + 'neovim/nvim-lspconfig', + requires = { + -- Automatically install LSPs to stdpath for neovim + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + + -- Useful status updates for LSP + 'j-hui/fidget.nvim', + + -- Additional lua configuration, makes nvim stuff amazing + 'folke/neodev.nvim', + }, + } + + use 'RRethy/nvim-base16' + + use 'xiyaowong/nvim-transparent' + + + + use { -- Autocompletion + 'hrsh7th/nvim-cmp', + requires = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, + } + + use { -- Highlight, edit, and navigate code + 'nvim-treesitter/nvim-treesitter', + run = function() + pcall(require('nvim-treesitter.install').update { with_sync = true }) + end, + } + + use { -- Additional text objects via treesitter + 'nvim-treesitter/nvim-treesitter-textobjects', + after = 'nvim-treesitter', + } + + use { -- rainbow brackets using treesitter + 'p00f/nvim-ts-rainbow', + after = 'nvim-treesitter' + } + + -- Git related plugins + use 'tpope/vim-fugitive' + use 'tpope/vim-rhubarb' + use 'lewis6991/gitsigns.nvim' + + use 'nvim-lualine/lualine.nvim' -- Fancier statusline + use 'lukas-reineke/indent-blankline.nvim' -- Add indentation guides even on blank lines + use 'numToStr/Comment.nvim' -- "gc" to comment visual regions/lines + use 'tpope/vim-sleuth' -- Detect tabstop and shiftwidth automatically + + if is_bootstrap then + require('packer').sync() + end + end) \ No newline at end of file diff --git a/nvim/lua/plugins/packer/init.lua b/nvim/lua/plugins/packer/init.lua deleted file mode 100644 index ecb84d4..0000000 --- a/nvim/lua/plugins/packer/init.lua +++ /dev/null @@ -1,62 +0,0 @@ -return require('packer').startup(function(use) - use 'wbthomason/packer.nvim' - use { - 'glepnir/dashboard-nvim', - config = [[require('plugins.dashboard')]] - } - use { - 'nvim-lualine/lualine.nvim', - requires = { - 'kyazdani42/nvim-web-devicons', - 'RRethy/nvim-base16' - }, - config = [[require('plugins.lualine')]] - } - use { - 'xiyaowong/nvim-transparent', - config = [[require('plugins.transparent')]] - } - use { - 'nvim-tree/nvim-tree.lua', - requires = { - 'nvim-tree/nvim-web-devicons', - }, - config = [[require('plugins.nvim-tree')]] - } - use { - 'nvim-treesitter/nvim-treesitter', - run = function() - local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) - ts_update() - end, - config = [[require('plugins.treesitter')]] - } - use 'p00f/nvim-ts-rainbow' - use 'jiangmiao/auto-pairs' - use { - 'williamboman/mason.nvim', - requires = { - 'neovim/nvim-lspconfig', - { - 'williamboman/mason-lspconfig.nvim', - config = [[require('plugins.mason.lspconfig')]] - }, - { - 'j-hui/fidget.nvim', - config = [[require('plugins.fidget')]] - } - }, - config = [[require('plugins.mason')]] - } - use { - 'hrsh7th/nvim-cmp', - requires = { - 'hrsh7th/cmp-nvim-lsp' - }, - config = [[require('plugins.cmp')]] - } - - if is_bootstrap then - require('packer').sync() - end -end) \ No newline at end of file diff --git a/nvim/lua/plugins/transparent/init.lua b/nvim/lua/plugins/transparent/init.lua deleted file mode 100644 index 6e1e360..0000000 --- a/nvim/lua/plugins/transparent/init.lua +++ /dev/null @@ -1,3 +0,0 @@ -require("transparent").setup({ - enable = true, - }) \ No newline at end of file diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..1321a6b --- /dev/null +++ b/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,65 @@ +require('nvim-treesitter.configs').setup { + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'help', 'javascript' }, + + highlight = { enable = true }, + indent = { enable = true, disable = { 'python' } }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + scope_incremental = '', + node_decremental = '', + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + [']m'] = '@function.outer', + [']]'] = '@class.outer', + }, + goto_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', + }, + goto_previous_start = { + ['[m'] = '@function.outer', + ['[['] = '@class.outer', + }, + goto_previous_end = { + ['[M'] = '@function.outer', + ['[]'] = '@class.outer', + }, + }, + swap = { + enable = true, + swap_next = { + ['a'] = '@parameter.inner', + }, + swap_previous = { + ['A'] = '@parameter.inner', + }, + }, + }, + rainbow = { + enable = true, + extended_mode = true, + max_file_lines = nil, + } + } \ No newline at end of file diff --git a/nvim/lua/plugins/treesitter/init.lua b/nvim/lua/plugins/treesitter/init.lua deleted file mode 100644 index 7821587..0000000 --- a/nvim/lua/plugins/treesitter/init.lua +++ /dev/null @@ -1,12 +0,0 @@ -require'nvim-treesitter.configs'.setup { - ensure_installed = { "vim", "c", "lua", "kotlin", "javascript", "typescript" }, - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, - rainbow = { - enable = true, - extended_mode = true, - max_file_lines = nil, - } - } \ No newline at end of file