From 1b168540726dc76a67ab6380d6fedbc3c3ede371 Mon Sep 17 00:00:00 2001 From: Timo Zimmermann Date: Mon, 8 Jan 2024 17:56:30 +0100 Subject: [PATCH] Add init.lua --- init.lua | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 init.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..e0ca8a0 --- /dev/null +++ b/init.lua @@ -0,0 +1,200 @@ +-- External tools: +-- ripgrep https://github.com/BurntSushi/ripgrep +-- bat https://github.com/sharkdp/bat +-- fd https://github.com/sharkdp/fd +-- +-- Debian: apt install ripgrep bat fdfind +-- ln -s $(which fdfind) /home/timo/bin/fd + + +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" + +-- bootstrap lazy if it is not installed +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath }) +end +vim.opt.rtp:prepend(vim.env.LAZY or lazypath) + + +-- remap leader +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' +vim.keymap.set({ 'n', 'v' }, '', '') + + +-- plugins +require("lazy").setup({ + { "chriskempson/base16-vim", lazy = true }, + { "nvim-tree/nvim-web-devicons", lazy = true }, + { "catppuccin/nvim", lazy = true, name = "catppuccin", priority=1000 }, + + { "akinsho/toggleterm.nvim", event = "VeryLazy", version = "*", + opts = { + size = 10, + open_mapping = "", + } + }, + + { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' } + }, + + {'akinsho/bufferline.nvim', version = "*", dependencies = 'nvim-tree/nvim-web-devicons'}, + + { 'echasnovski/mini.nvim', version = false }, + { 'echasnovski/mini.nvim', version = false }, + { "lukas-reineke/indent-blankline.nvim", main = "ibl", opts = {} }, + + { "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + }, + config = function() + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + + require('mason').setup() + local mason_lspconfig = require 'mason-lspconfig' + mason_lspconfig.setup { + ensure_installed = { "pyright" } + } + require("lspconfig").pyright.setup { + capabilities = capabilities, + } + end + }, + + { "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip" + }, + config = function() + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local cmp = require('cmp') + local luasnip = require('luasnip') + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + completion = { + autocomplete = false + }, + mapping = cmp.mapping.preset.insert ({ + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + 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" }), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select=true }), + }), + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + } + }) + end + }, + + { "nvim-treesitter/nvim-treesitter", version = false, + build = function() + require("nvim-treesitter.install").update({ with_sync = true }) + end, + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "python", "javascript" }, + auto_install = false, + highlight = { enable = true, additional_vim_regex_highlighting = false }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = "", + node_decremental = "", + } + } + }) + end + }, + + { "nvim-telescope/telescope.nvim", cmd = "Telescope", version = false, + dependencies = { "nvim-lua/plenary.nvim" }, + keys = { + { "sf", "Telescope git_files", desc = "Find Files (root dir)" }, + { "", "Telescope buffers", desc = "Find Buffers" }, + { "sg", "Telescope live_grep", desc = "Search Project" }, + { "ss", "Telescope lsp_document_symbols", desc = "Search Document Symbols" }, + { "sw", "Telescope lsp_dynamic_workspace_symbols", desc = "Search Workspace Symbols" }, + }, + opts = { + extensions = { + fzf = { + fuzzy = true, + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "smart_case" + } + } + } + }, + { "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + config = function() + require('telescope').load_extension('fzf') + end + }, + + { "jose-elias-alvarez/null-ls.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + config = function() + local null_ls = require("null-ls") + + null_ls.setup({ + sources = { + null_ls.builtins.diagnostics.ruff, + null_ls.builtins.formatting.black, + } + }) + end + }, +}) + + +-- theme +vim.cmd [[colorscheme catppuccin]] + + +-- LSP +vim.keymap.set('n', 'rn', vim.lsp.buf.rename, {desc = 'Rename Symbol'}) +vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {desc = 'Goto Definition'}) +vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, {desc = 'Code Action'}) +vim.keymap.set('n', 'K', vim.lsp.buf.hover, {desc = 'Hover Documentation'}) +vim.keymap.set('n', 'ff', vim.lsp.buf.format, {desc = 'Format Code'}) \ No newline at end of file