From 7ed897230bd89b47b0f4e4a5f49a1642b79de055 Mon Sep 17 00:00:00 2001 From: Nikurasu Date: Fri, 17 Feb 2023 10:59:38 +0100 Subject: [PATCH] Made neovim config far simpler --- nvim/init.lua | 136 +++++++++++--------------- nvim/lua/plugins/autoclose.lua | 1 - nvim/lua/plugins/cmp.lua | 41 -------- nvim/lua/plugins/comment.lua | 1 - nvim/lua/plugins/dashboard.lua | 1 - nvim/lua/plugins/fidget.lua | 1 - nvim/lua/plugins/gitsigns.lua | 9 -- nvim/lua/plugins/indent_blankline.lua | 4 - nvim/lua/plugins/init.lua | 14 --- nvim/lua/plugins/jabs.lua | 1 - nvim/lua/plugins/lualine.lua | 8 -- nvim/lua/plugins/mason.lua | 72 -------------- nvim/lua/plugins/nvim-tree.lua | 5 - nvim/lua/plugins/packer.lua | 77 --------------- nvim/lua/plugins/toggleterm.lua | 25 ----- nvim/lua/plugins/treesitter.lua | 65 ------------ 16 files changed, 59 insertions(+), 402 deletions(-) delete mode 100644 nvim/lua/plugins/autoclose.lua delete mode 100644 nvim/lua/plugins/cmp.lua delete mode 100644 nvim/lua/plugins/comment.lua delete mode 100644 nvim/lua/plugins/dashboard.lua delete mode 100644 nvim/lua/plugins/fidget.lua delete mode 100644 nvim/lua/plugins/gitsigns.lua delete mode 100644 nvim/lua/plugins/indent_blankline.lua delete mode 100644 nvim/lua/plugins/init.lua delete mode 100644 nvim/lua/plugins/jabs.lua delete mode 100644 nvim/lua/plugins/lualine.lua delete mode 100644 nvim/lua/plugins/mason.lua delete mode 100644 nvim/lua/plugins/nvim-tree.lua delete mode 100644 nvim/lua/plugins/packer.lua delete mode 100644 nvim/lua/plugins/toggleterm.lua delete mode 100644 nvim/lua/plugins/treesitter.lua diff --git a/nvim/init.lua b/nvim/init.lua index 9cb09e1..df8493f 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,16 +1,26 @@ --- Install packer +-- install packer if not already there 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 is_bootstrap = true - vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path } + vim.fn.system{'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path } vim.cmd [[packadd packer.nvim]] end --- When we are bootstrapping a configuration, it doesn't --- make sense to execute the rest of the init.lua. --- --- You'll need to restart nvim, and then it will work. +-- Install Plugins +require('packer').startup(function(use) + use 'wbthomason/packer.nvim' + use 'neovim/nvim-lspconfig' + use 'nvim-treesitter/nvim-treesitter' + use { + 'hrsh7th/nvim-cmp', + requires = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua' } + } + if is_bootstrap then + require('packer').sync() + end +end) + +-- Don't run additional config if installing packer if is_bootstrap then print '==================================' print ' Plugins are being installed' @@ -20,81 +30,53 @@ if is_bootstrap then return end --- 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', -}) - --- [[ Setting options ]] --- See `:help vim.o` - --- Set highlight on search -vim.o.hlsearch = false - --- Make line numbers default +-- Some basic settings vim.wo.number = true +vim.wo.relativenumber = true --- Enable mouse mode -vim.o.mouse = 'a' +-- Additional keybinds if lsp running +local on_attach = function(client, bufnr) + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) +end --- Enable break indent -vim.o.breakindent = true +local lsp_flags = { + +} --- Save undo history -vim.o.undofile = true +-- lsp configs +require('lspconfig')['tsserver'].setup{ + on_attach = on_attach, + flags = lsp_flags +} --- Case insensitive searching UNLESS /C or capital in search -vim.o.ignorecase = true -vim.o.smartcase = true +require('lspconfig')['lua_ls'].setup{ + on_attach = on_attach, + flags = lsp_flags +} --- Decrease update time -vim.o.updatetime = 250 -vim.wo.signcolumn = 'yes' +require('lspconfig')['gopls'].setup{ + on_attach = on_attach, + flags = lsp_flags +} --- Set colorscheme -vim.o.termguicolors = true -vim.cmd [[colorscheme base16-tomorrow-night-eighties]] +-- TreeSitter Config +require('nvim-treesitter.configs').setup{ + ensure_installed = {'go', 'vim', 'typescript', 'help', 'lua', 'javascript', 'python'}, + highlight = { + enable = true + } +} --- Set completeopt to have a better completion experience -vim.o.completeopt = 'menuone,noselect' - -vim.g.loaded_netrw = 1 - --- [[ 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) - -local api = require("nvim-tree.api") -vim.keymap.set('n', 'ft', api.tree.toggle) - -require('plugins') - --- 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) - --- disable some stock plugins -vim.g.loaded_netrwPlugin = 1 +-- autocompletion +local cmp = require 'cmp' +cmp.setup { + sources = { + { name = 'nvim_lsp' }, + { name = 'buffer' }, + { name = 'cmdline' }, + { name = 'path' }, + { name = 'nvim-lua' } + } +} diff --git a/nvim/lua/plugins/autoclose.lua b/nvim/lua/plugins/autoclose.lua deleted file mode 100644 index b194d21..0000000 --- a/nvim/lua/plugins/autoclose.lua +++ /dev/null @@ -1 +0,0 @@ -require("autoclose").setup({}) diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua deleted file mode 100644 index 732a6c1..0000000 --- a/nvim/lua/plugins/cmp.lua +++ /dev/null @@ -1,41 +0,0 @@ -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/comment.lua b/nvim/lua/plugins/comment.lua deleted file mode 100644 index d2af0f2..0000000 --- a/nvim/lua/plugins/comment.lua +++ /dev/null @@ -1 +0,0 @@ -require('Comment').setup() \ No newline at end of file diff --git a/nvim/lua/plugins/dashboard.lua b/nvim/lua/plugins/dashboard.lua deleted file mode 100644 index f55f7f3..0000000 --- a/nvim/lua/plugins/dashboard.lua +++ /dev/null @@ -1 +0,0 @@ -local db = require('dashboard') diff --git a/nvim/lua/plugins/fidget.lua b/nvim/lua/plugins/fidget.lua deleted file mode 100644 index 427cdec..0000000 --- a/nvim/lua/plugins/fidget.lua +++ /dev/null @@ -1 +0,0 @@ -require('fidget').setup() \ No newline at end of file diff --git a/nvim/lua/plugins/gitsigns.lua b/nvim/lua/plugins/gitsigns.lua deleted file mode 100644 index 356c415..0000000 --- a/nvim/lua/plugins/gitsigns.lua +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 8cd798d..0000000 --- a/nvim/lua/plugins/indent_blankline.lua +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 60c02b1..0000000 --- a/nvim/lua/plugins/init.lua +++ /dev/null @@ -1,14 +0,0 @@ -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') -require('plugins.nvim-tree') -require('plugins.toggleterm') -require('plugins.dashboard') -require('plugins.autoclose') -require('plugins.jabs') diff --git a/nvim/lua/plugins/jabs.lua b/nvim/lua/plugins/jabs.lua deleted file mode 100644 index af2c68b..0000000 --- a/nvim/lua/plugins/jabs.lua +++ /dev/null @@ -1 +0,0 @@ -require 'jabs'.setup {} diff --git a/nvim/lua/plugins/lualine.lua b/nvim/lua/plugins/lualine.lua deleted file mode 100644 index cc7036f..0000000 --- a/nvim/lua/plugins/lualine.lua +++ /dev/null @@ -1,8 +0,0 @@ -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/mason.lua b/nvim/lua/plugins/mason.lua deleted file mode 100644 index dda5baa..0000000 --- a/nvim/lua/plugins/mason.lua +++ /dev/null @@ -1,72 +0,0 @@ -require('mason').setup() - --- LSP settings. --- This function gets run when an LSP connects to a particular buffer. ---vim.keymap.set('n', 'rn', vim.lsp.buf.rename) -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('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - - 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 - -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), -} - -mason_lspconfig.setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = capabilities, - on_attach = on_attach, - settings = servers[server_name], - } - end, -} diff --git a/nvim/lua/plugins/nvim-tree.lua b/nvim/lua/plugins/nvim-tree.lua deleted file mode 100644 index c0f33e5..0000000 --- a/nvim/lua/plugins/nvim-tree.lua +++ /dev/null @@ -1,5 +0,0 @@ -require("nvim-tree").setup({ - filters = { - dotfiles = true, - }, -}) \ No newline at end of file diff --git a/nvim/lua/plugins/packer.lua b/nvim/lua/plugins/packer.lua deleted file mode 100644 index 090db1d..0000000 --- a/nvim/lua/plugins/packer.lua +++ /dev/null @@ -1,77 +0,0 @@ -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 'm4xshen/autoclose.nvim' - - 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 { - 'nvim-tree/nvim-tree.lua', - requires = { - 'nvim-tree/nvim-web-devicons', -- optional, for file icons - }, - } - - use { - 'akinsho/toggleterm.nvim' - } - - use { -- rainbow brackets using treesitter - 'p00f/nvim-ts-rainbow', - after = 'nvim-treesitter' - } - - use { - 'glepnir/dashboard-nvim' - } - - -- 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 - use 'matbme/JABS.nvim' - - if is_bootstrap then - require('packer').sync() - end - end) diff --git a/nvim/lua/plugins/toggleterm.lua b/nvim/lua/plugins/toggleterm.lua deleted file mode 100644 index be3ba29..0000000 --- a/nvim/lua/plugins/toggleterm.lua +++ /dev/null @@ -1,25 +0,0 @@ -require("toggleterm").setup({ - direction = 'horizontal' -}) - -function _G.set_terminal_keymaps() - local opts = {buffer = 0} - vim.keymap.set('t', '', [[]], opts) - vim.keymap.set('t', 'jk', [[]], opts) - vim.keymap.set('t', '', [[wincmd h]], opts) - vim.keymap.set('t', '', [[wincmd j]], opts) - vim.keymap.set('t', '', [[wincmd k]], opts) - vim.keymap.set('t', '', [[wincmd l]], opts) -end - -vim.cmd "autocmd! TermOpen term://* lua set_terminal_keymaps()" -local Terminal = require("toggleterm.terminal").Terminal -local lazygit = Terminal:new { cmd = 'lazygit', hidden = true, direction = 'float' } - - -function _LAZYGIT_TOGGLE() - lazygit:toggle() -end - -vim.keymap.set('n', 'tg', _LAZYGIT_TOGGLE) -vim.keymap.set('n', 'tt', 'ToggleTerm', {silent = true}) diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua deleted file mode 100644 index 1321a6b..0000000 --- a/nvim/lua/plugins/treesitter.lua +++ /dev/null @@ -1,65 +0,0 @@ -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